我正在使用jqGrid显示带有subGrid选项的Grid,在subGrid中我将单个列标记为Key,问题是当我使用远程单元格编辑时,发送到web服务的rowid是错误的(类似“jqg1”的东西,而“beforeSubmitCell”事件中的rowid是正确的,请帮忙,检查下面的代码,谢谢所有....
$("#tb_JQ").jqGrid({
url: "WebServices/WS_MonthlyFrcst.asmx/GetPlanGrouped",
datatype: "JSON",
postData: { PId: frcstId, PType: 1 },
mtype: "POST",
colNames: ["tableID", "Team", "Expense", "U/P", "Currency", "Quantity", "Value",
"JAN", "Quantity", "FEB", "Quantity", "MAR", "Quantity", "APR", "Quantity", "MAY", "Quantity", "JUN", "Quantity",
"JUL", "Quantity", "AUG", "Quantity", "SEP", "Quantity", "OCT", "Quantity", "NOV", "Quantity", "DEC", "Quantity"],
colModel: [
{ name: "tableID", editable: false, key: true, hidden: true },
{ name: "Team", width: 80 }, { name: "License", index: 'License', width: 250 },
{ name: "UP", width: 75 }, { name: "Currency", width: 60 }, { name: "Quantity", width: 80 },
{ name: "Value", width: 80 },
{ name: "JAN", width: 75, hidden: true }, { name: "JAN_Quan", width: 60, hidden: true }, { name: "FEB", width: 75, hidden: true },
{ name: "FEB_Quan", width: 60, hidden: true }, { name: "MAR", width: 75, hidden: true }, { name: "MAR_Quan", width: 60, hidden: true },
{ name: "APR", width: 75, hidden: true }, { name: "APR_Quan", width: 60, hidden: true }, { name: "MAY", width: 75, hidden: true },
{ name: "MAY_Quan", width: 60, hidden: true }, { name: "JUN", width: 75, hidden: true }, { name: "JUN_Quan", width: 60, hidden: true },
{ name: "JUL", width: 75, hidden: true }, { name: "JUL_Quan", width: 60, hidden: true }, { name: "AUG", width: 75, hidden: true },
{ name: "AUG_Quan", width: 60, hidden: true }, { name: "SEP", width: 75, hidden: true }, { name: "SEP_Quan", width: 60, hidden: true },
{ name: "OCT", width: 75, hidden: true }, { name: "OCT_Quan", width: 60, hidden: true }, { name: "NOV", width: 75, hidden: true },
{ name: "NOV_Quan", width: 60, hidden: true }, { name: "DEC", width: 75, hidden: true }, { name: "DEC_Quan", width: 60, hidden: true }
],
cmTemplate: { sortable: false, editable: false },
viewrecords: true,
width: 'auto',
height: 'auto',
loadonce: true,
gridview: false,
subGrid: true,
caption: 'EXP',
afterInsertRow: function (rowid, aData, rowElem) {
// Some sort of boolean flag, maybe a row count on your sub grid data
//alert(rowid);
if (rowid == 'NoExpandExp') {
$('#' + rowid).children("td.sgcollapsed").unbind().html("").removeClass("ui-sgcollapsed sgcollapsed");
}
},
subGridRowExpanded: function (subgrid_id, row_id) {
var rowData = $("#tb_JQ").getRowData(row_id);
var team = rowData.tableID;
var subgrid_table_id;
subgrid_table_id = subgrid_id + "_t";
var pager_id = "p_" + subgrid_table_id;
var tempCellOldVal;
$("#" + subgrid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + pager_id + "' class='scroll'></div>");
jQuery("#" + subgrid_table_id).jqGrid({
url: "WebServices/WS_MonthlyFrcst.asmx/GetBudgetBrkDown",
datatype: "JSON",
mtype: "POST",
colNames: ["EntryId", "Team", "Expense", "U/P", "Currency", "Quantity", "Value",
"JAN", "Quantity", "FEB", "Quantity", "MAR", "Quantity", "APR", "Quantity", "MAY", "Quantity", "JUN", "Quantity",
"JUL", "Quantity", "AUG", "Quantity", "SEP", "Quantity", "OCT", "Quantity", "NOV", "Quantity", "DEC", "Quantity"],
colModel: [
{ name: "EntryId", index: "EntryId", hidden: true },
{ name: "Team", width: 78 }, { name: "License", width: 250, editable: true, edittype: 'select',
editoptions: { value: GetProducts(frcstId) }
},
{ name: "UP", width: 75 },
{ name: "Currency", width: 60 }, { name: "Quantity", width: 75 }, { name: "Value", width: 80 },
{ name: "JAN", width: 75, hidden: true }, { name: "JAN_Quan", width: 60, hidden: true }, { name: "FEB", width: 75, hidden: true },
{ name: "FEB_Quan", width: 60, hidden: true }, { name: "MAR", width: 75, hidden: true }, { name: "MAR_Quan", width: 60, hidden: true },
{ name: "APR", width: 75, hidden: true }, { name: "APR_Quan", width: 60, hidden: true }, { name: "MAY", width: 75, hidden: true },
{ name: "MAY_Quan", width: 60, hidden: true }, { name: "JUN", width: 75, hidden: true }, { name: "JUN_Quan", width: 60, hidden: true },
{ name: "JUL", width: 75, hidden: true }, { name: "JUL_Quan", width: 60, hidden: true }, { name: "AUG", width: 75, hidden: true },
{ name: "AUG_Quan", width: 60, hidden: true }, { name: "SEP", width: 75, hidden: true }, { name: "SEP_Quan", width: 60, hidden: true },
{ name: "OCT", width: 75, hidden: true }, { name: "OCT_Quan", width: 60, hidden: true }, { name: "NOV", width: 75, hidden: true },
{ name: "NOV_Quan", width: 60, hidden: true }, { name: "DEC", width: 75, hidden: true }, { name: "DEC_Quan", width: 60, hidden: true }
],
id: 'EntryId',
height: '100%',
loadComplete: function () {
$(".ui-jqgrid-hdiv", "#gbox_" + this.id).hide();
var tempIdx = colStructObject.AppliedGrids.indexOf('#' + this.id);
if (tempIdx > -1)
colStructObject.AppliedGrids.splice(tempIdx, 1);
colStructObject.AppliedGrids.push('#' + this.id);
tempIdx = editableGrids.indexOf('#' + this.id);
if (tempIdx > -1)
editableGrids.splice(tempIdx, 1);
editableGrids.push('#' + this.id);
hideCols();
opeEditCols();
//setHiddenCols('#' + this.id);
},
cmTemplate: { sortable: false, editable: false },
loadonce: true,
postData: { budgetId: frcstId, divisionId: team, productType: 1 },
width: 'auto',
loadonce: true,
pager: pager_id,
rowList: [],
pgbuttons: false,
pgtext: null,
viewrecords: false,
'cellEdit': true,
'cellsubmit': 'remote',
cellurl: "WebServices/WS_MonthlyFrcst.asmx/CellUpdate",
afterSaveCell: function (a, b, c, d, e) {
$("#" + subgrid_table_id).trigger("reloadGrid");
$("#tble_DevitMnth").trigger("reloadGrid");
$("#tbl_GrandTotal").trigger("reloadGrid");
},
beforeSubmitCell: function (rowid, cellname, value, iRow, iCol) {
if (!isNumber(value))
restoreCell(iRow, iCol);
}
//'Handler.ashx?function=UpdateCell'
});
$("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id, { del: false, edit: false, refresh: true, search: false, add: false });
$("#" + subgrid_table_id).jqGrid('navGrid', "#" + pager_id).jqGrid('navButtonAdd', "#" + pager_id, {
caption: '', buttonicon: "ui-icon-plus",
onClickButton: function () {
//var emptyItem = [{ Cat_Id: catId, Category: catNm, Team: "T1", TotalAmount: amount}];
$("#" + subgrid_table_id).jqGrid('addRowData', 0, [{}]);
// $("#dialog").dialog("open");
// $.ajax({
// dataType: "json",
// url: 'Handler.ashx?function=AddEmpty&Team=' + team
// });
//$("#" + subgrid_table_id).trigger("reloadGrid");
},
position: "first", title: "Add New Row", cursor: "pointer"
});
}
});
答案 0 :(得分:0)
您在子网格中使用cellEdit: true
选项 ,且子网格不包含任何具有key: true
属性的列。您可能需要将key: true
添加到EntryId
列吗?可能是在子网格中包含jsonReader: {id: "EntryId"}
可以替代地解决问题。在这种情况下,您甚至可以从子网格中删除不需要的隐藏列EntryId
。