jqGrid inline editing event on "Esc" cancel

gurun8 picture gurun8 · Apr 27, 2010 · Viewed 10k times · Source

Does anyone know if jqGrid inline editing throws events that can be handled? The following code is a simple example of what I'm trying to accomplish:

jQuery('#list').jqGrid('editRow', 0, true, false, false, false, {onClose: function(){alert('onClose')}}, reloadGrid);

I'd like to be able to handle an "Esc" cancel event. The onClose event is available with Form Editing:

See the respective section in jqGrid's documentation.

but doesn't work with inline editing and the Inline Editing documentation doesn't supply anything event wise other than the extraparam option which is very unspecific:

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:inline_editing

I haven't been able to figure out how to utilize the extraparam options. Suggestions?

Answer

Justin Ethier picture Justin Ethier · Apr 27, 2010

According to your link:

extraparam: an array of type name: value. When set these values are posted along with the other values to the server.

So this is only going to allow you to pass custom data back to the server via a POST. It will not allow you to add an event handler.

The jqGrid source code for editRow contains the following handler for the Escape key:

if (e.keyCode === 27) {$($t).jqGrid("restoreRow",rowid, afterrestorefunc);}

So an event is raised. According to the docs:

afterrestorefunc if defined this function is called in after the row is restored. To this function we pass the rowid

So there is not an explicit function callback for the escape key, although pressing escape will trigger afterrestorefunc. Unfortunately this event is also called when a row is saved via the Enter key:

if (e.keyCode === 13) {
    var ta = e.target;
    if(ta.tagName == 'TEXTAREA') return true;
    $($t).jqGrid("saveRow",rowid,succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc );
    return false;
}

But if you are careful you may be able to use afterrestorefunc to meet your needs.