取消选择单元格的奇怪行为

Weird Bahavior for onSelectCell

我注意到 cellEdit: true 时 onSelectCell 中有一个奇怪的行为。

我在一个简单的表单上有 2 个网格,第二个网格在用户 select 之后从第一个开始加载一行。两个网格都将 cellEdit 设置为 true,我正在使用 onSelectCell 从第一个网格中捕获 rowid,因此我可以调用一个方法来检索相应的数据。

奇怪的行为是:

在第一行select它return rowid = undefined !

On first cell select

当我select从第一个网格开始另一行时,onSelectCell 事件将前一行值分配给 rowid。

On second cell select

这种行为正常吗??我在文档中读到它(仅适用于不可编辑的单元格;在单元格 selected 后触发)这正是我想要它做的。

// 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");
                }
            }
        })

我也包含了网格的代码,以防我犯错,它可能是 -_-

感谢您的宝贵时间。

看来您正在设置 selectedCodevalidator 变量 第二个网格的 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);
},