jqgrid change cell value and stay in edit mode

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.

Leave a Comment