Search code examples
jqgridjqgrid-inlinenav

jqGrid inline editing - addRow keys not working for the first time


I want to use inline editing with Esc and Enter keys and I'm using inlineNav method. I already set keys: true for editRow method and keys are working. While I'm usig "add row" button, keys are not forking for the first time. I must cancel this operation by mouse and when I tried to add row again, keys are working normally. I have no clue how to debug this. It's jqGrid v. 4.4.4

$("myGrid").jqGrid(finalConfig)
  .navGrid(gridToolbar).inlineNav(gridToolbar, {
     editParams: { keys: true }
  }
);

Solution

  • If you want to define some common settings for inline editing I would recommend you to use $.jgrid.inlineEdit. For example

    $.extend($.jgrid.inlineEdit, { keys: true });
    

    In the case you will have Enter key working in any form of usage of inline editing. In the case inline editing activated per formatter: "actions" will works in the same way like Add and Edit buttons added by inlineNav.

    Alternatively you have to specify special for inlineNav the option for "add row" button in the following way

    $("#myGrid").jqGrid("inlineNav", "#pager", {
        editParams: { keys: true },
        addParams: { addRowParams: { keys: true } }
    });
    

    Typically one defines all inline editing options in one object and uses the same options object twice:

    var editingOptions = { keys: true };
    
    $("#myGrid").jqGrid("inlineNav", "#pager", {
        editParams: editingOptions,
        addParams: { addRowParams: editingOptions }
    });
    

    See the answer for more code examples.

    UPDATED: I think I found the reason why you had keys: false used during Add operation at the beginning, but had later keys: false working. The reason is the bug which I described in the bug report which I just posted. You can try to use fixed version of jquery.jqGrid.src.js (you can get it here). The reason was that

    1. inlineNav has one bug: it uses always editParams inside of "Cancel" event handler (see the line) even if we cancel "Add" operation. So the method restoreRow was called with editParams as parameter.
    2. The next bug is that the line of restoreRow changes $.jgrid.inlineEdit instead of just usage it. To fix the bug one have to change the line
    o = $.extend(true, $.jgrid.inlineEdit, o );
    

    to

    o = $.extend(true, {}, $.jgrid.inlineEdit, o);