【发布时间】:2016-02-10 19:18:49
【问题描述】:
我注意到 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");
}
}
})
我也包含了网格的代码,以防我犯了任何错误,它可能是-_-
感谢您的宝贵时间。
【问题讨论】:
标签: javascript jquery jqgrid