The problem is that you are trying to implement cell editing with a double click, which is not supported. Your current code does not work, because if the user presses the Tab , Enter or Esc keys , the nextCell , prevCell , saveCell or restoreCell will actually be called, but the methods will be checked internally with the cellEdit parameter true .
To show how to fix the problem, I created a demo that uses the following code:
cellsubmit: 'clientArray', ondblClickRow: function (rowid, iRow, iCol) { var $this = $(this); $this.jqGrid('setGridParam', {cellEdit: true}); $this.jqGrid('editCell', iRow, iCol, true); $this.jqGrid('setGridParam', {cellEdit: false}); }, afterEditCell: function (rowid, cellName, cellValue, iRow) { var cellDOM = this.rows[iRow], oldKeydown, $cellInput = $('input, select, textarea', cellDOM), events = $cellInput.data('events'), $this = $(this); if (events && events.keydown && events.keydown.length) { oldKeydown = events.keydown[0].handler; $cellInput.unbind('keydown', oldKeydown); $cellInput.bind('keydown', function (e) { $this.jqGrid('setGridParam', {cellEdit: true}); oldKeydown.call(this, e); $this.jqGrid('setGridParam', {cellEdit: false}); }); } }
UPDATED . If you want to undo or save the latest editing changes, if the user clicks on any other cell, you need to expand the code as follows:
beforeSelectRow: function (rowid, e) { var $this = $(this), $td = $(e.target).closest('td'), $tr = $td.closest('tr'), iRow = $tr[0].rowIndex, iCol = $.jgrid.getCellIndex($td); if (typeof lastRowIndex !== "undefined" && typeof lastColIndex !== "undefined" && (iRow !== lastRowIndex || iCol !== lastColIndex)) { $this.jqGrid('setGridParam', {cellEdit: true}); $this.jqGrid('restoreCell', lastRowIndex, lastColIndex, true); $this.jqGrid('setGridParam', {cellEdit: false}); $(this.rows[lastRowIndex].cells[lastColIndex]) .removeClass("ui-state-highlight"); } return true; }
New demo shows results.
UPDATED 2 . Alternatively, you can use focusout to undo or save the latest editing changes. See another demo that uses code:
ondblClickRow: function (rowid, iRow, iCol) { var $this = $(this); $this.jqGrid('setGridParam', {cellEdit: true}); $this.jqGrid('editCell', iRow, iCol, true); $this.jqGrid('setGridParam', {cellEdit: false}); }, afterEditCell: function (rowid, cellName, cellValue, iRow, iCol) { var cellDOM = this.rows[iRow].cells[iCol], oldKeydown, $cellInput = $('input, select, textarea', cellDOM), events = $cellInput.data('events'), $this = $(this); if (events && events.keydown && events.keydown.length) { oldKeydown = events.keydown[0].handler; $cellInput.unbind('keydown', oldKeydown); $cellInput.bind('keydown', function (e) { $this.jqGrid('setGridParam', {cellEdit: true}); oldKeydown.call(this, e); $this.jqGrid('setGridParam', {cellEdit: false}); }).bind('focusout', function (e) { $this.jqGrid('setGridParam', {cellEdit: true}); $this.jqGrid('restoreCell', iRow, iCol, true); $this.jqGrid('setGridParam', {cellEdit: false}); $(cellDOM).removeClass("ui-state-highlight"); }); } }
UPDATED 3 . Starting with jQuery 1.8, you need to use $._data($cellInput[0], 'events'); instead of $cellInput.data('events') to get a list of all the events of $cellInput .