我有一个导航网格,使用从控制器收到的JSON数据填充。这些数据作为JSON存储在数据库中的单列中。
$('#list-grid').jqGrid({
url: '@Url.Action("MyAction", "MyController")',
mtype: 'GET',
postData: { parameter1: para1, parameter2:para2 },
datatype: 'json',
gridview: true,
caption: ' ',
height: '100%',
multiselect: true,
rowNum: 5000,
viewrecords: true,
//colmodel and colnames
});
现在,我已将导航栏添加到网格中。
jQuery("#list-grid").jqGrid('navGrid', '#list-grid3-pager',
{ edit: true, add: true, del: true, refresh: true, search: false, view: false, refreshtitle: "Clear filters", edittitle: "Edit selected record", addtitle: "Add new record" },
{
//this code executes on 'Submit' button in the dialog
//here, the selected row should be edited and edit should be reflected in the grid---in client-side
//then the whole grid has to be serialized,
//one more parameters has to be added
//and finally posted to the controller
}//edit option
使用单独的AJAX调用,单独使用'保存'按钮,我可以像下面这样发送网格数据,虽然这个网格仍然没有新编辑/添加的数据:
$("#btnSave").click(function () {
var gridData = jQuery("#list-grid").getRowData();
var postGridData = JSON.stringify(gridData);
jQuery.ajax({
type: "POST",
url: '@Url.Action("MyAction2", "MyController")',
data: JSON.stringify({ parameter1: para1, gridValues: postGridData }),
contentType: "application/json; charset=utf-8",
dataType: "json",
});
}
我的问题:
如何在导航网格中添加/编辑行,并在每次添加/编辑Submit
单击后,对整个网格进行字符串化(添加的记录应该在那里,如果任何行已编辑,则字符串应包含更改了值而不是旧值,添加参数然后将其传递给控制器(就像在ajax调用中看到的那样)?