下面的代码在ext3.0中可以,可是到了3.1,总是报ed为Null的错误。但是tab键却可以。
Ext.override(Ext.grid.RowSelectionModel, {
onEditorKey : function(field,e) {
// alert('go');
var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
var shift = e.shiftKey;
//判断校验如果没有通过,不能走动。焦点停在原地,
//Ext.log('k:' + k);
if (k == e.ENTER) {
//alert("回车后,单元格焦点位置事件1");
//alert(grid.activeEditor.field.isValid(true));
e.stopEvent();
ed.completeEdit();
if (shift) {
newCell = g.walkCells(ed.row, ed.col - 1, -1,
this.acceptsNav, this);
} else {
// alert('go');
//alert("回车后,单元格焦点位置事件2");
newCell = g.walkCells(ed.row, ed.col + 1, 1,
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);
}
}
} else if (k == e.ESC) {
ed.cancelEdit();
}
if (newCell) {
g.startEditing(newCell[0], newCell[1]); //newCell是一个数组,包含了rowIndex,colIndex
}
}
});
方法重写啊,这个你得去看RowSelectionModel的源码了,我估计是你这里的enter事件之前editor就被销毁了。下面是3.2的那一段代码:
[code="js"]
else if(k == e.ENTER){
if(this.moveEditorOnEnter !== false){
if(shift){
newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
}else{
newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
}
}
}
[/code]
里面根本就没有使用对Editor的引用