【问题标题】:ExtJs - keep grid row selected while editExtJs - 在编辑时保持选中网格行
【发布时间】:2013-03-12 14:56:35
【问题描述】:

我通过收听文本字段的change 来更改网格中id 列的值:

oTextfieldName.on( 'change', function( oField, strValue ) {
   oStore.getAt( 0 ).setId( strValue );
}

但是,如果调用 setId(),则删除该行 0 的选择。我的应用程序依赖于选定的行来保持选中状态。

如何在保持选中行的同时仍编辑/更改该 id 列?


编辑:

当使用store.sync() 时,它会重新被选中。

但是,我的商店乱扔了:

Uncaught TypeError: Object function () { this.destroy = Ext.emptyFn; } has no method 'indexOf' ext-dev.js:1253

【问题讨论】:

    标签: extjs extjs4 extjs4.1


    【解决方案1】:

    你能重新选择行吗?

    oTextfieldName.on( 'change', function( oField, strValue ) {
       oStore.getAt( 0 ).setId( strValue );
       yourGrid.getSelectionModel().select(0);
    }
    

    您也可以执行类似的操作来禁止触发选择事件。

    var suppressEvent = true;
    yourGrid.getSelectionModel().select(rowIndex, null, suppressEvent);  
    

    查看SelectionModel select method 的文档

    这是一个简单的fiddle,你可以玩。如果您单击“测试”按钮,它将选择索引 1 处的行。

    【讨论】:

    • 谢谢。我试过了,没有用。我仍然不知道如何让编辑状态恢复正常。查看我的编辑。
    【解决方案2】:

    由于sync()导致了这个错误,我现在就用那个糟糕的方式:

    oSelectionModel.deselect( nIndex, true );        
    oSelectionModel.select( nIndex, true );
    

    更改后,我取消选择(幸运的是不可见)然后选择。至少它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多