IE11 的 jqGrid 问题 - 当用户从可编辑单元格中跳出时,第一个键输入忽略

jqGrid issue with IE11 - First key enter ignore when user tab out from editable cell

我在 IE11 中遇到一个奇怪的问题,它忽略了可编辑单元格中输入的第一个字符。
用例是,当用户在 jqGrid 单元格中输入一些数据并按 TAB,然后我们再次使同一单元格可编辑。问题是,当单元格再次变得可编辑时,它总是会忽略第一个键入的字符。

var mydata = [{
    name: "Toronto",
    country: "Canada",
    continent: "North America"
}, {
    name: "New York City",
    country: "USA",
    continent: "North America"
}, {
    name: "Silicon Valley",
    country: "USA",
    continent: "North America"
}, {
    name: "Paris",
    country: "France",
    continent: "Europe"
}]

var gridCtrl = $("#grid").jqGrid({
    data: mydata,
    datatype: "local",
    colNames: ["Name", "Country", "Continent"],
    colModel: [{
        name: 'name',
        index: 'name',
        editable: true,
    }, {
        name: 'country',
        index: 'country',
        editable: true,
    }, {
        name: 'continent',
        index: 'continent',
        editable: true,
    }],
    pager: '#pager',    
    cellEdit: true,
    cellsubmit: 'clientArray',
    afterEditCell: GridAfterEditCell,
    beforeSaveCell: GridBeforeSaveCell,
    afterRestoreCell: GridAfterRestoreCell,
    afterSaveCell: GridAfterSaveCell
});

function GridAfterEditCell(rowid, cellname, value, iRow, iCol) {
}

function GridAfterSaveCell(rowid, cellname, value, iRow, iCol) {
}

function GridBeforeSaveCell(rowid, cellname, value, iRow, iCol) {    
    alert('some validation alert!!!');
    setTimeout(function(){
        // refocus on the same cell
        gridCtrl.jqGrid('editCell', rowid, iCol, true);
    }, 10);
    return value;    
}

function GridAfterRestoreCell(rowid, value, iRow, iCol) {    
}

这是 jsfiddle 代码 link: 演示:http://jsfiddle.net/CzVVK/2225/

步数:

  1. 在 IE11
  2. 中打开 link
  3. 输入数据第一个单元格
  4. TAB
  5. 它将显示警报并再次使同一单元格可编辑
  6. 现在按任意键(即输入字符a
  7. 您会注意到您输入的第一个字符被忽略了!!!

您在演示中使用旧的 jqGrid 4.6。这是错误,已在 free jqGrid. Look at the modified demo http://jsfiddle.net/OlegKi/CzVVK/2230/. The new demo uses URLs of free jqGrid 4.10.0 from CDN (see the wiki article).

中修复

我修复了 beforeSaveCell 回调的代码,以使用 iRow 而不是 rowid,您将其用作 editCell 的参数:

function GridBeforeSaveCell(rowid, cellname, value, iRow, iCol) {    
    var $grid = $(this);
    alert('some validation alert!!!');
    setTimeout(function(){
        // refocus on the same cell
        $grid.jqGrid('editCell', iRow, iCol, true);
    }, 10);
    return value;    
}