Using jqGrid I want to open a cell-editor on double-click, so my code includes this part:
ondblClickRow: function(rowid, iRow, iCol, e)
{
jQuery('#jqGrid').setGridParam({cellEdit: true});
jQuery('#jqGrid').editCell(iRow, iCol, true);
jQuery('#jqGrid').setGridParam({cellEdit: false});
}
which works fine, but I don’t know how to (auto-) close the cell-editor, when user click outside of the edit element, or press ESC, TAB, ENTER, etc…
The problem is that you try to implement cell editing on double-click which is not supported. Your current code don’t work because if the user press Tab, Enter or Esc key the
nextCell,prevCell,saveCellorrestoreCellwill be really called, but the methods tests internally whethercellEditparameter istrue.To show how to fix the problem I created the demo which uses the following code:
UPDATED: If you want to discard or save the last editing changes if the user click on any other cell one should extend the code with the following:
The new demo shows the results.
UPDATED 2: Alternatively you can use
focusoutto discard or save the last editing changes. See one more demo which use the code:UPDATED 3: Starting with jQuery 1.8 one should use
$._data($cellInput[0], 'events');instead of$cellInput.data('events')to get the list of all events of$cellInput.