[英]How to save one row's data to the server after inline editing in jqGrid?
我已經看到了@Oleg 的幾乎所有示例和答案,但還沒有真正找到解決方案。 這是我的網格-
$(grid).jqGrid({
datatype: 'local',
mtype: 'GET',
url: "/Views/MyUrl",
editUrl: "/Views/MyEditUrl",
colNames: colNames,
colModel: colModel,
altRows: false,
pager: $(pager),
loadonce: true,
sortable: true,
multiselect: false,
viewrecords: true,
shrinkToFit: false,
gridView: true
// onSelectRow: editRow
}).navGrid(pager, { add: false, edit: false, del: false, search: false}
$grid.jqGrid('inlineNav', pager, {
edit: true,
add: true,
del: true,
cancel: true,
save: true,
editParams: {
keys: false
},
addParams: {
keys: true
}
});
我正在使用jqGrid 4.6 版本和內聯行編輯。
我嘗試了 'onselectRow',其中我調用了 'saveRow' 而不是 'restoreRow' ,這也不起作用。
編輯該行后,我想將整行數據發送回控制器以在數據庫中更新。 現在,它甚至沒有命中控制器方法。
請參閱此處的鏈接
您必須將數據保存在函數 oneditfunc 回調上
$(grid).jqGrid({
...
onSelectRow: function(id){
if(id && id!==lastSel){
jQuery('#grid_id').restoreRow(lastSel);
lastSel=id;
}
$(grid).jqGrid('editRow',rowid,
{
keys : true,
oneditfunc: function() {
alert('Edit Complete');
},
beforeSaveRow: function (o, rowid) {
// this is where you should save the data
// Do validation and save the data here
// Note, the 'beforeSaveRow' is undocumented, but it gets invoked before jqGrid calls its own SaveRow method.
// Get data by rowid and save it to DB and then
grid.saveRow(rowid, false);
return false;// To avoid jqgrid from invoking its own save again
},
aftersavefunc: function (rowid) {
// this fired is after saving
var rowData = $this.jqGrid("getRowData", rowid);
}
},
...
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.