English 中文(简体)
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 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?

最佳回答

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.





相关问题
Listen for Events from Browser "Find" Window in JavaScript

Is there a way to listen for typing into the browser s "find" window in JavaScript? (source: apple.com) I d like to be able to reinterpret the search text from JavaScript. What do I need to ...

Equivalent of PreviewKeyDown of C# needed for native C++/MFC

I used a ActiveXControl in a C# Forms application and had the possibility to implement a PreviewKeyDown event handler for that ActiveXControl. That was needed to specify that, e.g. the [ALT] key, is ...

Refresh the UI in gwt

I have created some custom composite widget, which listens to an events (in my case loginEvent). Once the event is caught the state of the widget changes so as the way it should look (in my case I ...

How to remove "onclick" with JQuery?

PHP code: <a id="a$id" onclick="check($id,1)" href="javascript:void(0)" class="black">Qualify</a> I want to remove the onclick="check($id,1) so the link cannot be clicked or "check($id,...

热门标签