PDA

View Full Version : EditorGridPanel loses cell focus after esc key



mohaaron
16 Sep 2009, 2:58 PM
I have been having this problem for a while now where when I was editing a cell (CellSelectionModel) and I hit the ESC key the grid would lose focus and I could not move around the grid using the arrow keys anymore.

I found that if I overrode the CellSelectionModel onEditorKey function with a slight change it works. I don't know if anyone else is having this problem but here is the fix. I don't know if this is the best solution but it does work.



Ext.override(Ext.grid.CellSelectionModel, {
onEditorKey : function(field, e){
var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
if(k == e.TAB){
if(e.shiftKey){
newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
}else{
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
e.stopEvent();
}else if(k == e.ENTER){
ed.completeEdit();
e.stopEvent();
}else if(k == e.ESC){
e.stopEvent();
ed.cancelEdit();
g.getView().focusCell(ed.row, ed.col);
}
if(newCell){
g.startEditing(newCell[0], newCell[1]);
}
}
});

mohaaron
17 Sep 2009, 11:24 AM
I just made another addition to this that allows entering new data into a cell and then using the up and down arrow keys to move out of the current cell, complete the edit, then move up or down into the next cell to be edited. This is handy when you have a column of cells that need to be quickly edited.

I'm currently using this in combination with the AutoEditGrid here http://www.extjs.com/forum/showthread.php?p=387926.

what I'm slowly working towards is an editing grid that can be navigated in much the same way as Excel. So far I have some pieces but am still far from my ultimate goal. I will start a new thread which lists all the pieces I have and functionality I want soon.



Ext.override(Ext.grid.CellSelectionModel, {
onEditorKey : function(field, e){
var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
if(k == e.TAB){
if(e.shiftKey){
newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
}else{
newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
}
e.stopEvent();
}else if(k == e.ENTER){
ed.completeEdit();
e.stopEvent();
}else if(k == e.ESC){
e.stopEvent();
ed.cancelEdit();
g.getView().focusCell(ed.row, ed.col); // Added BY: Aaron Prohaska, 2009.09.16.15:30
}else if(k == e.DOWN){ // Added BY: Aaron Prohaska, 2009.09.17.11:30
ed.completeEdit();
e.stopEvent();
newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
}else if(k == e.UP){ // Added BY: Aaron Prohaska, 2009.09.17.11:30
ed.completeEdit();
e.stopEvent();
newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
}
if(newCell){
g.startEditing(newCell[0], newCell[1]);
}
}
});