extjs3.1以后版本 在grid中 用Enter实现Tab导航

网上发布的一些extjs 在grid中 用Enter实现Tab 的方法,如下面的网址

http://blog.csdn.net /traceofsun/archive/2010/08/13/5808648.aspx, 但是在extjs3.1以后 ,此类方法失效提示ed为null,经过查证,稍加修改(注意红色加粗部分代码),现在可以正常使用,与大家共饷


/*
作者:eycbest
时间:20100907
网址:http://www.cnblogs.com/eycbest
*/
Ext.override(Ext.grid.RowSelectionModel, {
                onEditorKey : 
function(field, e) {
                    
// alert('go');
                    //alert( this.grid.activeEditor);
                     
                    
var k = e.getKey(), newCell, g = this.grid,= g.lastEdit, ed = g.activeEditor;
                    
var shift = e.shiftKey;
                    
//Ext.log('k:' + k);
                    
                    
if(ed){
                    }
else{
                        ed
=l;
                    }
                    
                    
if (k == e.ENTER) {
                        e.stopEvent();
                        
if(ed){
                            
//ed.completeEdit();
                        }
                        
if (shift) {
                            newCell 
= g.walkCells(ed.row, ed.col - 1-1,
                                    
this.acceptsNav, this);
                        } 
else {
                            
// alert('go');
                            newCell = g.walkCells(ed.row, ed.col + 11,
                                    
this.acceptsNav, this);
                        }
                    } 
else if (k == e.TAB) {
                        e.stopEvent();
                        ed.completeEdit();
                        
if (this.moveEditorOnEnter !== false) {
                            
if (shift) {
                                newCell 
= g.walkCells(ed.row - 1, ed.col, -1,
                                        
this.acceptsNav, this);
                            } 
else {
                                
// alert('go');
//
                                newCell = g.walkCells(ed.row + 1, ed.col, 1,
//
                                        this.acceptsNav, this);
                                newCell = g.walkCells(ed.row, ed.col + 11,
                                    
this.acceptsNav, this);
                            }
                        }
                    } 
else if (k == e.ESC) {
                        ed.cancelEdit();
                    }
                    
if (newCell) {
                        g.startEditing(newCell[
0], newCell[1]);
                    }
                }
            });
    
var sm2 = new Ext.grid.RowSelectionModel({
        moveEditorOnEnter : 
true,
        singleSelect : 
true,
        listeners : {
            rowselect : 
function(sm, row, rec) {
                centerForm.getForm().loadRecord(rec);
            }
        }

    });
    



 

 

posted @ 2010-09-07 09:17  二月草  阅读(1299)  评论(0编辑  收藏  举报