我有一个主网格(可编辑),主网格的每一行调用一个子网格(也可编辑),它根据主网格的rowid从DB加载数据。 我必须使用'ClientArray'选项在本地保存数据,一旦用户点击保存,我会提取所有数据并保存。 问题是,如果用户折叠了一行,我会丢失子网格中的所有已编辑数据。我试过,loadonce = true,但还没有运气。
非常感谢任何建议。
代码:
WeightsGridHome = {
setupGrid: function(grid) {
grid.jqGrid({
url: CRITERIAGRID_DATA_URL,
editurl: "",
mtype: "POST",
ajaxGridOptions: { contentType: "application/json" },
ajaxRowOptions: { contentType: "application/json; charset=utf-8", dataType: "json" },
datatype: "json",
cellEdit: true,
viewrecords: true,
forceFit: true,
cellsubmit: 'clientArray',
serializeGridData: function(postData) {
var propertyName, propertyValue, dataToSend = {};
postData.searchFilter = Sys.Serialization.JavaScriptSerializer.serialize(searchFilter);
for (propertyName in postData) {
if (postData.hasOwnProperty(propertyName)) {
propertyValue = postData[propertyName];
if ($.isFunction(propertyValue)) { dataToSend[propertyName] = propertyValue(); }
else { dataToSend[propertyName] = propertyValue }
}
}
return JSON.stringify(dataToSend);
},
success: function(data, st) { if (st == "success") { var grid = $("#weightsGrid")[0]; grid.addJSONData(JSON.parse(data.d)); } },
// this is what jqGrid is looking for in json callback
jsonReader: {
repeatitems: false,
root: function(obj) { return Sys.Serialization.JavaScriptSerializer.deserialize(obj.d); }
},
colNames: getWeightColumnHeadings(),
colModel: getWeightColumns(),
rowNum: 100000,
caption: "JSON Example",
subGridBeforeExpand: function(pID, id) {
searchFilter.CriteriaID = id;
},
// Start of SUBGRID
subGrid: true,
// define the icons in subgrid
subGridOptions: {
"plusicon": "ui-icon-triangle-1-e",
"minusicon": "ui-icon-triangle-1-s",
"openicon": "ui-icon-arrowreturn-1-e"
},
subGridRowColapsed: function(pID, id) {
//debugger;
selectedRowID = "";
//return ValidateSaveWeights();
},
subGridRowExpanded: function(subgrid_id, row_id) {
alert(subgrid_id)
var subgrid_table_id;
var pager_id;
subgrid_table_id = subgrid_id + "_t";
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");
jQuery("#" + subgrid_table_id).jqGrid({
url: CRITERIASUBGRID_DATA_URL, //CRITERIASUBGRID_DATA_URL
mtype: 'POST',
ajaxGridOptions: { contentType: "application/json" },
ajaxRowOptions: { contentType: "application/json; charset=utf-8", dataType: "json" },
datatype: "json",
cellEdit: true,
viewrecords: true,
forceFit: true,
cellsubmit: 'clientArray',
loadonce: true,
serializeGridData: function(postData) {
var propertyName, propertyValue, dataToSend = {};
//I've added this line to handle adding an extra parameter for searching...
//there will be a better way to do this
//if (postData["searchFilter"] == undefined) {
// postData.searchFilter = searchFilter.ID;
// alert("tow");
//}
postData.searchFilter = Sys.Serialization.JavaScriptSerializer.serialize(searchFilter);
for (propertyName in postData) {
if (postData.hasOwnProperty(propertyName)) {
propertyValue = postData[propertyName];
if ($.isFunction(propertyValue)) { dataToSend[propertyName] = propertyValue(); }
else { dataToSend[propertyName] = propertyValue }
}
}
return JSON.stringify(dataToSend);
},
success: function(data, st) { if (st == "success") { var grid = $("#weightsGrid")[0]; grid.addJSONData(JSON.parse(data.d)); } },
// this is what jqGrid is looking for in json callback
jsonReader: {
repeatitems: false,
// id: "id",
root: function(obj) { /*alert(obj.d);*/return Sys.Serialization.JavaScriptSerializer.deserialize(obj.d); }
},
colNames: getWeightColumnHeadings(),
colModel: getWeightSubColumns(),
rowNum: 100000,
sortname: 'id',
sortorder: "asc",
loadComplete: function() {
setColumnsEditable(jQuery("#" + subgrid_table_id))
subGridID = "#" + subgrid_table_id;
},
gridComplete: function() {
$(".ui-jqgrid-hdiv", "#gview_" + subgrid_table_id).hide();
$(".ui-jqgrid-bdiv").height("auto");
},
onSelectRow: function(id) {
//alert('row2');
}
})
}
//End SUBCRITERIA
}
);