2009-09-04 111 views
2

我正在網格上進行內聯編輯,但似乎無法獲取任何與該編輯關聯的事件。jqGrid:爲什麼我沒有爲網格編輯定義的事件?

在這裏,我有afterSubmit:我希望它在用戶編輯網格中的數量字段後觸發,但它從不觸發。

$('#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成功並返回結果,它從來沒有遇到應該綁定到它的事件。我已經嘗試了所有與數量字段更改相關的事件,但都沒有工作。

我在正確的地方定義了事件嗎?我在網格上丟失了一個屬性嗎?

回答

8

我認爲你需要將afterSubmit中的properties參數傳遞給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的editRow方法簽名/ grid.inlineedit.js

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

我認爲你是在正確的軌道上。但是,editRow語句曾經有兩個參數.editRow(id,true)。布爾型「真」參數發生了什麼?沒有它,該單元似乎不再提交。 – 2009-09-04 23:15:16

+0

對不起,應該是editGridRow。 – seth 2009-09-04 23:32:30

+0

我希望避免一個彈出框。理想情況下,希望在網格中獲得內聯編輯的行爲。 – 2009-09-04 23:39:29

1

你也可以在editRow方法中使用aftersavefunc事件來獲得服務器響應,如果這是你正在尋找的唯一的東西。