我注意到onSelectCell中的一个奇怪的行为,而cellEdit:true。
我在一个简单的表单上有2个网格,第二个网格在用户从第一个表单中选择一行后加载。两个网格都将cellEdit设置为true,并且我使用onSelectCell从第一个捕获rowid,所以我可以调用一个方法来检索相应的数据。
奇怪的行为是:
在第一行选择它返回rowid = undefined!
当我从第一个网格中选择另一行时,onSelectCell事件会将前一行值分配给rowid。
这种行为是正常的吗?我在文档中读到了它(仅适用于不可编辑的单元格;选中单元格后触发),这正是我想要它做的事情。
// First Grid ...
pGrid.jqGrid({
url: 'empty.json',
datatype: 'local',
myType: 'POST',
colNames: ['rn', 'dirty', 'Code', 'Description', 'SPIFF Amount', 'GSA-SIN', 'Is Active Hidden', 'Is Active'],
colModel: [
{ name: 'ROWID', index: 'ROWID', width: 50, hidden: true }, // this can be removed ... but i'm too lazy to do it.
{ name: 'dirty', index: 'dirty', width: 50, hidden: true },
//this is the field that i'm clicking -- i'm disabling the cells in the column using another peice of code.
//even if i remove the editable:true the situation still the same.
{ name: 'Code', index: 'Code', align: 'left', width: 120, search: true, editable: true },
{ name: 'Description', index: 'Description', align: 'left', width: 400, search: true, editable: true },
],
jsonReader: {
root: 'data', id: 'Code', multiselect: false, repeatitems: false
},
rownumbers: true,
loadonce: true,
cellEdit: true,
cellsubmit: 'clientArray',
sortable: true,
ignoreCase: true,
height: 200,
rowNum: 1000,
width: null,
shrinkToFit: false,
gridview: true,
emptyrecords: 'No records to display',
altRows: false,
rowList: [],
pgbuttons: false,
pgtext: null,
viewrecords: true,
hidegrid: false,
scrollrows: true,
pager: $('#productPager'),
onSelectCell: function (rowid, celname, value, iRow, iCol) {
//Here i'm loading the second grid
ProductCode.Main.populateProductAccounts(rowid);
validator = $.parseJSON(ProductCode.Main.AccountValidator(rowid).responseText).data[0].CanChangeAccount;
// here i'm assigning the rowid to a global variable
selectedCode = rowid;
},
beforeEditCell: function (rowid, cellname, value, iRow, iCol) {
originalRow = pGrid.jqGrid('getRowData', rowid);
},
afterSaveCell: function (rowid, cellname, value, iRow, iCol) {
//some code has nothing to do with the situation
},
gridComplete: function () {
allowRowEdit();
}
}).jqGrid('navGrid', '#pager', { add: false, edit: false, del: false }, {}, {}, {}, { multipleSearch: true })
.jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: 'cn' });;;
pGrid.jqGrid('filterToolbar', { clearSearch: true });
pGrid[0].toggleToolbar();
}

// Second Grid ...
paGrid.jqGrid({
url: 'empty.json',
datatype: 'local',
myType: 'POST',
colNames: ['Row', 'Account Type', 'Account ID', 'Description'],
colModel: [
{ name: 'Row', index: 'Row', hidden: true },
{ name: 'AccountType', index: 'AccountType', align: 'left', width: 150 },
{ name: 'Account', index: 'Account', align: 'left', width: 150, editable: true },
{ name: 'AccountName', index: 'AccountName', align: 'left', width: 639 },
],
jsonReader: {
root: 'data', id: 'Row', multiselect: false, repeatitems: false
},
rownumbers: true,
cellEdit: true,
loadonce: true,
cellsubmit: 'clientArray',
sortable: true,
ignoreCase: true,
height: 115,
rowNum: 20,
width: null,
shrinkToFit: false,
gridview: true,
emptyrecords: 'No records to display',
altRows: false,
rowList: [],
pgbuttons: false,
pgtext: null,
viewrecords: true,
hidegrid: false,
scrollrows: true,
ondblClickRow: function (id) {
if (validator == 'N' && id == 3) { return; }
ProductCode.Account.OpenDialog(id);
},
afterSaveCell: function (id, cellName, value, iRow, iCol) {
//some code has nothing to do with the situation
},
gridComplete: function () {
// I need to disable a AccountName in the 3rd row if the validator is 'N'
alert(validator + ' - ' + selectedCode);
if (validator == 'N' && validator != undefined) {
paGrid.jqGrid('setCell', 3, 'Account', '', 'not-editable-cell');
paGrid.jqGrid('setCell', 3, 'AccountName', paGrid.jqGrid("getCell", 3, 'AccountName') + " - Account can't be changed");
}
}
})

如果我犯了任何错误,我也会包含网格的代码,它可能是-_-
感谢您的时间。
答案 0 :(得分:0)
在触发第二个网格的selectedCode
事件后,您似乎正在设置validator
和gridComplete
变量。尝试更改顺序:
onSelectCell: function (rowid, celname, value, iRow, iCol) {
// here i'm assigning the rowid to a global variable
selectedCode = rowid;
validator = $.parseJSON(ProductCode.Main.AccountValidator(rowid).responseText).data[0].CanChangeAccount;
// do this last since it depends on the variables above
ProductCode.Main.populateProductAccounts(rowid);
},