下面的代码在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
}
}
});