如何在Ext JS 3网格中捕获Tab键按下事件

时间:2013-11-27 09:51:16

标签: extjs extjs3

我尝试捕捉Tab键按下事件。这就是我试过的:

this.test.on('keypress', function(t,e) {
    if (e.getKey() == Ext.EventObject.ENTER) {
        alet('kk');
    }
}, this);

请帮助抓住网格单元格中的Tab键按下事件。

This my EditorGridPanel override function

         Ext.override(Ext.grid.EditorGridPanel, {
            initEvents : function(){
               Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
               this.on("bodyscroll", this.stopEditing, this, [true]);
               this.on("columnresize", this.stopEditing, this, [true]);
               this.view.scroller.on("mousedown", this.onMouseDownEditClick, this);

               this.on('keypress', function(t,e) {
//                  if (e.getKey() == Ext.EventObject.TAB) {
                      alert('kk');
//                  }
               }, this);                

               //Reload datastore without redrawing grid
               this.getView().on('beforerefresh', function(view) {
                 view.scrollTop = view.scroller.dom.scrollTop;
                 view.scrollHeight = view.scroller.dom.scrollHeight;
               });
               this.getView().on('refresh', function(view) {
                   setTimeout(function () {
                       view.scroller.dom.scrollTop = view.scrollTop + (view.scrollTop == 0 ? 0 : view.scroller.dom.scrollHeight - view.scrollHeight);
                   }, 100);
               });

                if(this.clicksToEdit == 'mousedown'){
                    this.view.scroller.on("mousedown", this.onMouseDownEditClick, this);
                }else   if(this.clicksToEdit == 1){
                    this.on("cellclick", this.onCellDblClick, this);
                }else {
                    if(this.clicksToEdit == 'auto' && this.view.mainBody){
                        this.view.mainBody.on("mousedown", this.onAutoEditClick, this);
                    }
                    this.on("celldblclick", this.onCellDblClick, this);
                }
            },
            onMouseDownEditClick : function(e, t){
               if(e.button !== 0){
                  return;
               }
               var row = this.view.findRowIndex(t);
               var col = this.view.findCellIndex(t);
               edit_row = row;
               edit_col = col;
               if(row !== false && col !== false){
                  this.startEditing(row, col);
               }
            }

         }); 

2 个答案:

答案 0 :(得分:0)

我在你的代码中看到拼写错误。代替

alet('kk');

使用

alert('kk');

但无论如何,你是否试图使用类似的东西?

this.test.on('keypress', function(t,e) {
   if (e.getKey() == Ext.EventObject.TAB) {
       alert('kk');
   }
}, this);

答案 1 :(得分:0)

我有一个类似的问题,因为'按键'事件仅在EditorGridPanel(而不是单个单元格)上发生事件时触发。

我将事件监听器放在EditorGridPanel的GridView上,具体来说,就我的目的而言,是为了听取'rowupdated'事件(http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.grid.GridView-event-rowupdated) - 我希望这有助于其他人。