javascript 如何确定 ExtJS 4 中 Ext.grid.Panel 的选定单元格?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6042176/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 19:15:18  来源:igfitidea点击:

How to determine the selected cell of a Ext.grid.Panel in ExtJS 4?

javascriptextjsextjs4

提问by Sebastian

how can i get the selected cell of a Ext.grid.Panel? In ExtJS 3 it was possible via:

如何获取 Ext.grid.Panel 的选定单元格?在 ExtJS 3 中,可以通过:

grid.getSelectionModel().getSelectedCell()

In Ext 4 there is

在 Ext 4 中有

grid.getSelectionModel().selected

but this only gives me the record.

但这只能给我记录。

回答by Craig

There may be a more direct way to do this but the following seems to work for me:

可能有更直接的方法来做到这一点,但以下似乎对我有用:

grid.view.getCellByPosition(grid.getSelectionModel().getCurrentPosition());

回答by stagl

I ended up needing the actual column that the user was clicking on and discovered the following:

我最终需要用户单击的实际列并发现以下内容:

grid.panel.columns[grid.getSelectionModel().getCurrentPosition().column]

Don't forget to apply:

不要忘记申请:

    selType : 'cellmodel'

to your grid to make sure you can select cells!

到您的网格以确保您可以选择单元格!

回答by Ahmed MEZRI

Use the beforeedit listener and context.record to get the desired row

使用 beforeedit 侦听器和 context.record 获取所需的行

this.editing = Ext.create('Ext.grid.plugin.CellEditing', {
        clicksToEdit: 1,
        listeners: {
            beforeedit: function (obj) {
                var MyColumnValue = obj.context.record.get('YourColumnName');
                 // or maybe to clear the value of this cell
                 obj.context.record.set('YourColumnName', null);
        }
      }
 });