问题
I have a navigation grid, populated using the JSON data received from the controller.This data is stored as a JSON in database in single column.
$('#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
});
Now, I have added navigation bar to the grid.
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
Using a separate AJAX call, with a separate 'Save' button, I could have done like following to send the grid data, although this grid would still not have newly edited/added data:
$("#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",
});
}
My Question:
How do I add/edit rows in navigation grid, and after each add/edit Submit
click, stringify the whole grid, (the added record should be there, and if any row has been edited, the string should contain the changed value and not the old one) , add a parameter and then pass it to the controller (just as you see in the ajax call) ?
来源:https://stackoverflow.com/questions/41181435/how-to-add-edit-rows-of-a-jqgrid-using-navigator-in-client-side-before-submitt