Extjs EditorGridPanel Tab键替换

问题  

  用方向键RIGHT代替Tab键,实现光标在gridpanel上的跳转

 

     

哈哈,既然Ext本身实现了Tab光标跳转,那直接去看源码就行了嘛

    终于,在ext-all-debug.js    第63598行找到了OnEditorKey这个函数

     简化后:   

 

// private
onEditorKey : function(field, e){
var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
if(k == e.TAB){
e.stopEvent();
ed.completeEdit();
newCell
= g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
if(newCell) g.startEditing(newCell[0], newCell[1]);
}

 

 

 

    这里的this指的是RowSelectionModel的对象,我们要用grid.getSelectionModel()来获得,于是问题可以这样解决:

    在editorGridPanel的column中,监听textfield的键盘事件

 

 

columns:[
   { header: 'xx', dataIndex: 'xx' },
   { header: 'xxx', dataIndex: 'xxx', editor: xxxxx.createdTextField() }
]
----------------------------

createTextField :
function() {
return new Ext.form.TextField({
listeners : {
keyup :
function(field, e) {
var k = e.getKey(), newCell, g = /*想办法得到编辑的grid*/, ed = g.activeEditor;
var selectionModel = g.getSelectionModel();
if(k == e.RIGHT){
newCell
= g.walkCells(ed.row, ed.col+1, 1, selectionModel.acceptsNav, selectionModel);
e.stopEvent();
}
if(newCell) g.startEditing(newCell[0], newCell[1]);
}
});
}

 

finished

posted @ 2009-12-08 21:15  tracy_cool  阅读(993)  评论(0)    收藏  举报