0

I'm using inline editing in my grid , I have some cases which i want to change the value of a cell inside a column. I'm changing it with setCell ,and it works good. my problem is that after the change the cell losts it's edit mode while all other cells of the row are in edit mode. I want to keep the cell in edit mode after i changed it.

for now what i did is saved the row and then selected it again and made in in edit mode - but i don't think it is a good solution - Is there a way to keep in edit mode while changin it?

Thank's In Advance.

user590586
  • 2,960
  • 16
  • 63
  • 96
  • Could you explain why it can be needed to save the contain of the cell which is in the editing mode. Typically if the user start changes in the cell he can click "Esc" to discard the changes. If the user click of "Enter" the changes will be saved, but in the case the row will be not more in the editing mode. Probably you use some another scenario for the saving the data. If you explain the scenario and describe **where** in which event handler you use the `setCell` call I could try to find a workaround for your situation. – Oleg Mar 09 '11 at 21:49
  • @Oleg:I will try to explain my situation-in my grid i have 2 cells which one of them is a code and the other is a description of the code. i have inside the code cell " $(elem).blur(function() " inside of it's 'editoptions:'. in this oblur function i make an ajax call to the server which gives me the description - then what i want to do is set the description cell with the value i got , and then continue editing the row i'm in - i want the next cell to get focue and continue editing. currently only the description cell loses it's editing and i want to keep it in edit mode, did u understand me? – user590586 Mar 10 '11 at 07:57

2 Answers2

5

If you need to implement the behavior of dependency cells which are all in the editing mode you have to modify the cell contain manually with respect of jQuery.html function for example. If the name of the column which you want to modify has the name "description", and you use 'blur' event on another "code" column then you can do about the following

editoptions: {
    dataEvents: [
        {
            type: 'blur',
            fn: function(e) {
                var newCodeValue = $(e.target).val();
                // get the information from any source about the
                // description of based on the new code value
                // and construct full new HTML contain of the "description"
                // cell. It should include "<input>", "<select>" or
                // some another input elements. Let us you save the result
                // in the variable descriptionEditHtml then you can use

                // populate descriptionEditHtml in the "description" edit cell
                if ($(e.target).is('.FormElement')) {
                    // form editing
                    var form = $(e.target).closest('form.FormGrid');
                    $("#description.FormElement",form[0]).html(descriptionEditHtml);
                } else {
                    // inline editing
                    var row = $(e.target).closest('tr.jqgrow');
                    var rowId = row.attr('id');
                    $("#"+rowId+"_description",row[0]).html(descriptionEditHtml);
                }
            }
        }
    ]
}

The code will work for both inline and form editing.

The working example of dependent <select> elements you can find here.

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @Oleg: thank's! but I didn't understand what should be the value of descriptionEditHtml ? can u give me an example? – user590586 Mar 10 '11 at 11:52
  • 1
    @user590586: It's depend on the formatter which you use in the column. It can be edit field, select element, checkbox and so on. In the simplest situation it is ` – Oleg Mar 10 '11 at 12:25
  • @Oleg: "$("#"+rowid+"_description").val("new description text")" is exactly what i need!! thanksssssss!! one more question - in which cases do i need to use "var row = $(e.target).closest('tr.jqgrow'); var rowId = row.attr('id');$("#"+rowId+"_description",row[0]).html(descriptionEditHtml);" like you wrote in the answer above? – user590586 Mar 10 '11 at 12:36
  • @user590586: You need in for example in case of "select" type of the "description" column. In the case you have no simple way to modify all "" of the " – Oleg Mar 10 '11 at 13:21
  • @Oleg: I have another question regarding this issue.. I have 2 grids inside my page , both of them have the same cell , how can i use "$("#"+rowid+"_description").val("new description text")" for a specific grid? thank's! – user590586 Mar 15 '11 at 10:51
  • 1
    @user590586: What do you mean under ", both of them have the same cell"? Do the sell contains identical? If you have the same `rowid` in both tables then you made an error: the `rowid` will be used as `id` attribute for the `` element of the grid. It is not permitted to use the same `id` attributes for more then one elements on the same page. – Oleg Mar 15 '11 at 10:58
  • @Oleg: I did give the same rowid , but i thought it is permitted beacuse they are in diffrent grids.. so i will change it. but I still want to know how do i set the cell value for a specific grid? is that possible? – user590586 Mar 15 '11 at 11:01
  • @user590586: If you have **unique ids** for all rows and you want change the sell in one grid you could just use `$("#grid1").jqGrid('setCell',rowid,colNameOrIndex,data)` to change the cell contain. In the case no cells from another grid will be changed because of wrong id resolution. – Oleg Mar 15 '11 at 11:14
  • @Oleg: I changed my row id to a diffrent one , thank's! but if i use $("#grid1").jqGrid('setCell',rowid,colNameOrIndex,data) the cell wont stay in edit mode like i want.. is "$("#"+rowid+"_description").val("new description text")" the only option? – user590586 Mar 15 '11 at 11:27
  • @user590586: Oh no! I didn't read the title of your original question. Of course you should use `$.val`, `$.html` to the change the value of the cell which is in editing mode. There are many ways to change contain of the DOM element on the page. If you use jQuery the functions like `$.val`, `$.html`, `$.val`, `$.text` seems me most suitable. – Oleg Mar 15 '11 at 11:41
  • @Oleg: so actually i don't really need to know which grid it is right? – user590586 Mar 15 '11 at 12:02
  • @user590586: In general, Yes, but I a little disagree with the formulation. You has the problem with id duplicate, so you has side effects. Now you can just do want you need and it will work correct. If you will modify one element on the page no other elements will be additionally changed, so you don't "need to know" which more elements (like grids) exist on the same page. – Oleg Mar 15 '11 at 12:35
  • @Avinash: You are welcome! I think that [the demo](http://www.ok-soft-gmbh.com/jqGrid/EditWithDependendSelects2_.htm) from [the answer](http://stackoverflow.com/a/4480184/315935) provides more recent version of dependent selects. – Oleg Nov 07 '13 at 13:26
0

blur does not fire if value is changed and enter is pressed immediately without moving to other cell. So better is to use

editrules = new
{
custom = true,
custom_func = function( val, col ) { ... }
 },

and move this code from blur to custom_func as described in jqgrid: how send and receive row data keeping edit mode

Community
  • 1
  • 1
Andrus
  • 26,339
  • 60
  • 204
  • 378