我必须在一页上添加两个 jqgrids。一个用于显示记录,另一个用于批量插入。我有一个网格,为了添加另一个网格,我刚刚在同一个文件中定义了另一个具有不同方法签名的初始化网格方法。发生的问题是当我单击添加行时,添加了两行而不是一行。该函数执行两次,负责添加一个新的空白行。我对 jquery 很陌生。任何帮助,将不胜感激。
function InitGrid1() {
debugger
// $grid1.find('.jqgrow td').live('click', function (e) {
// if (e.target && e.target.nodeName != 'TD') return;
// var $this = $(this);
// if ($this.find('input, a').length == 0)
// OnColumnClick($this);
// });
var lastSelectedRowID;
$grid1.jqGrid({
colNames: ['AttendancePolicyID', 'AllowedVariationID', 'New', 'Updated', 'Policy Enabled', 'Effective Date', 'Employee ID', 'Employee Name', 'Activity Type', 'After Start', 'Before End', 'Allowed Variation', 'Status', '', '', 'Payroll_f', '', ''],
colModel: colModel,
sortname: 'EffectiveDate',
sortorder: "DESC",
rowNum: 5000,
rownumbers: true,
rownumWidth: 30,
autowidth: true,
gridview: true,
jsonReader: {
root: "rows",
page: "page",
total: "totalpages",
records: "totalrecords",
cell: "cell",
id: "ID", //index of the column with the PK in it
userdata: "userdata",
repeatitems: true
},
prmNames: {
rows: "numRows",
page: "page",
sort: "sortField",
order: "sortOrder"
},
postData: {
employeeIDs: []
},
datatype: function (postdata) {
idsToDelete = new Array();
if (reloadType == GridReloadType.PastedFromExcel || reloadType == GridReloadType.ShowingResults) {
var griddata = {
totalpages: 1,
page: 1,
totalrecords: totalRowsToLoad,
rows: gridrows
}; fs
$grid1[0].addJSONData(griddata);
}
else if (reloadType == GridReloadType.LoadFromServer) {
LoadAttendancePolicyFromServerpanel(postdata);
}
else
LoadAttendancePolicyFromServerpanel(postdata);
},
gridComplete: function () {
}
});
var $html = $('#jqgh_attendancePolicyGrid_rn').html();
$('#jqgh_attendancePolicyGrid_rn').html('No.' + $html);
$('.ui-jqgrid-titlebar-close').remove();
DisableSaveButton(true);
ResizeGrid();
$(window).resize(function () {
ResizeGrid();
});
function OnColumnClick($col) {
try {
var $row = $col.parent('tr:first');
var rowid = $row.attr('id');
if (rowid == null || $row == null)
return;
if ($row.find('input').length > 1)
return;
SaveRow(lastSelectedRowID);
}
catch (ex) {
ShowMessage(ex.message);
}
}
}