jqGrid:为什么不是我为网格编辑定义的事件?

我正在对网格进行内联编辑,但似乎无法触发与该编辑相关的任何事件。

在这里我有afterSubmit:我希望它在用户编辑网格中的Quantity字段后触发,但它永远不会触发。

$('#tblLines').jqGrid({ url: createUrl('/CRA/GetLines/'), editurl: '/CRA/EditModifyLine', emptyrecords: '', datatype: 'json', mtype: 'GET', colNames: ['Group', 'Description', 'Quantity'], colModel: [ { name: 'Group', index: 'Group', width: 100, align: 'left' }, { name: 'Description', index: 'Description', width: 400, align: 'left' }, { name: 'Quantity', index: 'Quantity', width: 150, align: 'left', editable: true }, pager: jQuery('#pgrLines'), rowNum: 10, rowList: [5, 10, 20, 50], sortname: 'Group', sortorder: "desc", viewrecords: true, caption: 'Core Group Lines', onSelectRow: function(id) { $('#tblCoreGroupLines').editRow(id, true); lastsel = id; }, afterSubmit: function(response, postdata) { alert('got here'); }, postData: { craId: $('#CraId').val() } }); 

我已经尝试将事件定义为navControl的一部分,但这也不起作用。 内联编辑工作正常 – POST成功,结果返回,它只是永远不会发生应该绑定它的事件。 我已经尝试了所有与更改数量字段相关的事件,但它们都不起作用。

我是否在正确的位置定义了活动? 我错过了网格上的属性还是什么?

我认为你需要将属性参数中的afterSubmit传递给editRow

因此,您需要移动afterSubmit如下所示:

  ..... onSelectRow: function(id) { $('#tblCoreGroupLines').editGridRow(id, { afterSubmit: function(response, postdata) { alert('got here'); } }); lastsel = id; }, ... 

关于editGridRow的文档在这方面有所帮助。

上面的示例会导致模态(因为这是使用afterSubmit的唯一位置)。 如果您想在使用indline编辑成功更新后执行某些操作,则应该能够在onSelectRow中执行以下操作

  $('#tblCoreGroupLines').editGridRow(id,true, undefined, function(res) { // res is the response object from the $.ajax call alert('success!!') } ); 

这是来自js / grid.inlineedit.js的editRow的方法签名

  editRow : function(rowid,keys,oneditfunc,succesfunc, url, extraparam, aftesarvefunc,errorfunc, afterrestorefunc) { 

您还可以在editRow方法中使用aftersavefunc事件来获取服务器响应(如果这是您要查找的唯一内容)。