jqGrid包含在colmodel中定义的列
{"name":"_actions",
"formatoptions":{"editbutton":true,"keys":true
,"delbutton":true
} },
{ "name":"Kood","editable":true,"hidden":true}
Run Code Online (Sandbox Code Playgroud)
在工具栏中按下内联添加按钮的网格中添加了新行.保存数据后,控制器返回新的Kood列值.此新值应分配给Kood列.
下面的代码显示了我尝试的两种方法但都失败了.Kood列值不会改变
如何在内联添加后更新列?如果使用保存操作按钮保存内联添加的行,如何更新列?
$grid.jqGrid('inlineNav', '#grid_toppager', {
addParams: {
addRowParams: {
keys: true,
// This is called if enter key is pressed to save added row
aftersavefunc: afterSaveFuncAfterAdd,
}
},
editParams: {
keys: true,
// This is called if saver button in toolbar is pressed on inline add
aftersavefunc: afterSaveFuncAfterAdd,
},
add: true,
edit: false,
save: true,
cancel: true
});
function afterSaveFuncAfterAdd(rowID, response ) {
var json = $.parseJSON(response.responseText);
postData = $grid.jqGrid('getGridParam', 'postData');
// this shows correct value:
alert(json.PrimaryKeyValues[0]);
// attempt 1:
$('#' + rowID + '_Kood').val(json.PrimaryKeyValues[0]);
// attempt2:
postData['Kood'] = json.PrimaryKeyValues[0];
}
Run Code Online (Sandbox Code Playgroud)
回调aftersavefunc中的editRow会后和编辑的调用.目前你会发现没有$('#' + rowID + '_Kood').此外,postData在内联编辑期间不会更改,因此$grid.jqGrid('getGridParam', 'postData')不会为您提供有用的信息.
因此,我建议您回复所需的所有数据作为响应editurl.例如,具有服务器计算的默认值的列,如上次编辑时间戳,您可以回发.Add操作的响应还应包含id服务器生成的响应.您可以在收到服务器的响应后使用setRowData或setCell修改网格中的数据.
例如,您可以返回
{"Id": "DB_Id", "Kood": "new Kood value"}
Run Code Online (Sandbox Code Playgroud)
从服务器作为响应"添加"操作并返回
{"Kood": "new Kood value"}
Run Code Online (Sandbox Code Playgroud)
作为"编辑"操作的响应.在这种情况下,代码afterSaveFuncAfterAdd可以如下所示
var afterSaveFunc = function (rowId, response) {
var data = $.parseJSON(response.responseText);
if ($.isPlainObject(data) && typeof data.Kood !== "undefined") {
if (typeof data.Id !== "undefined") {
// if we have 'Id' column in the grid we have to update the column
// together with the value of `Kood`
$(this).jqGrid('setRowData', rowId, { Id: data.Id, Kood: data.Kood });
// if we have no additional `Id` we can update the Kood column only with
// the statement like below
// $(this).jqGrid('setCell', rowId, 'Kood', data.Kood);
// in case of "Add" operation we have to update the row Id
$('#' + $.jgrid.jqID(rowId)).attr('id', data.Id);
} else {
$(this).jqGrid('setCell', rowId, 'Kood', data.Kood);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5811 次 |
| 最近记录: |