我创建了Subgrid作为网格&用于向子网格添加行的自定义按钮。 如果我在单击/展开任何子网格后调用addRowData但是没有我不能插入任何行,就会创建行。
有没有办法插入行而不在子网格上展开/设置焦点。
已更新
流程:
我创建了子网格作为网格&在我使用的数据类型为“JSON”。
将subgridoption设置为this - subGridOptions:{expandOnLoad:false,selectOnExpand:false,reloadOnExpand:false}
点击我们的自定义按钮addRow调用gridComplete:
gridComplete: function(){
$("#addRow").click(function(e) {
var rowIds = $("#list2").getDataIDs();
$.each(rowIds, function (index, rowId) {
//Dynamically expanding it so that we can add new rows
$("#list2").expandSubGridRow(rowId);
});
});
}
subGridRowExpanded中的代码:
subGridRowExpanded: function (subgridId, rowId) {
var selr = jQuery('#list2').jqGrid('getGridParam', 'selrow');
var apid = jQuery('#list2').jqGrid('getCell', rowId, 'ActionPlanId');
var subgridTableId;
subgridTableId = subgridId + "_t";
jQuery("#" + subgridId).html("<table id='" + subgridTableId + "' class='scroll'></table>");
jQuery("#" + subgridTableId).jqGrid({
url: 'SomeServiceurl',
datatype: "json",
jsonReader: {
root: function (obj) {
return obj;
},
repeatitems: false
},
serializerGridData: function (postData) {
return JSON.stringify(postData);
},
colNames: [
'UniqueId',
'Column1',
'Column2',
'Column3',
],
colModel: [
{ name: 'UniqueId', index: 'UniqueId', width: 100, hidden: true },
{ name: 'Column1', index: 'Column1', width: 100 },
{ name: 'Column2', index: 'Column2', width: 200 },
{ name: 'Column3', index: 'Column3', width: 80, editable: true, editrules: { required: true, minValue: 1 }, align: "center" }
],
height: "auto",
loadonce: true,
rowNum: 20,
editurl: 'clientArray',
cellsubmit: 'clientarray',
onSelectRow: function (subgridId) {
var $this = $(this), p = $this.jqGrid("getGridParam"), rowData
rowData = $this.jqGrid("getRowData", subgridId);
},
});
},
我们在点击addRow按钮时调用的伪代码:
var addtrowdetails = function ()
{
//Getting the data
var data = [
[
Column1,
Column2,
Column3
]
];
var names =
[
"Column1",
"Column2",
"Column3"
];
//Assigning the data to myNewRowData
//Adding the rows
for (var i = LastCount1; i <= LastCount1; i++) {
$("#list2_" + subGridNo + "_t").jqGrid('addRowData', LastCount1, myNewRowData[i],'last');
}
//Incrementing the position for next use
LastCount1 += 1;
}