jqGrid inline editing event on "Esc" cancel
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 ver开发者_Go百科y 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?
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.
Hey Justin thanks for the prompt response and help.
Although the afterrestorefunc
callback shows promise to my inquiry it's still not exactly what I'm looking for at this point. As far as I can see the only why this would be beneficial is if I was invoking the restoreRow
method. But the problem I'm facing is that an editRow
is being closed via the "Esc" key and I need to be able to handle the event. However, your response got me thinking about the editRow
callbacks and there's a afterrestorefunc
callback definition there as well:
jQuery("#grid_id").jqGrid('editRow',rowid, keys, oneditfunc, succesfunc, url, extraparam, aftersavefunc,errorfunc, afterrestorefunc);
This is exactly what I need and appears to be working perfectly. Although your answer wasn't a 100% fit to my question it definitely pointed me in the right direction. Thanks for the help.
精彩评论