PDA

View Full Version : Detecting key modifiers in grid cell editor?



nsolsen
29 Jun 2010, 6:08 AM
Dear Community,

I'm having a hard time distinguishing between TAB and SHIFT-TAB in a 'specialkey' listener on a grid cell editor. I have tried this column config:



...
{
dataIndex: 'foo',
editor: {
xtype: 'numberfield',

listeners: {
specialkey: function(field, e) {
if(e.getKey() === e.TAB) {
console.log("TAB...");
}
}
}
}
},
...
As far as I can see from the API docs, there is no way to detect key modifiers such as SHIFT/ALT/CTRL in the EventObject. Am I missing something here?

I have tried using an Ext.KeyMap. It is possible to set up the bindings so that they only trigger if certain key modifiers are active. But it seems that the KeyMap bindings do not trigger at all when in a grid cell editor. I have tried adding the KeyMap to the grid using the 'keys' config, and also to the global 'document' element. In both cases the handler is invoked fine, except when the grid cell editor has focus.. :s

Any help on this would be greatly appreciated..

Context: I am trying to implement a grid for efficient data entry. When the user TABs out of the last editor cell in the last row, I want to catch this and add a new row, which is initialized with some of the data copied from the previous row. Obviously this should not happen on SHIFT-TAB.

Any suggestions for an alternative strategy is very welcome indeed!

Thanks,
Niels

nsolsen
30 Jun 2010, 11:39 AM
No community input on this?

I'm thinking the EventObject class ought to have methods to determine which key modifiers are active. Is this viable?

mankz
30 Jun 2010, 11:32 PM
You can check these properties to find out if shift or CTRL is pressed on a keydown event (didn't find info about it in the docs, which might be a documentation bug actually):



e.ctrlKey
e.shiftKey

nsolsen
1 Jul 2010, 3:14 AM
You can check these properties to find out if shift or CTRL is pressed on a keydown event (didn't find info about it in the docs, which might be a documentation bug actually):



e.ctrlKey
e.shiftKey


Thanks! Works like a charm. :)

I agree that these modifier properties (shiftKey/ctrlKey/altKey) should be in the EventObject documentation. Ideally they should have getter methods like getKey(), getCharCode(), getTarget() et al.

/Niels