PDA

View Full Version : KeyPress event from a Grid



marswe
26 Aug 2008, 6:50 AM
Is it possible to add a listener to a Grid and then react when a user press Enter to select a row in a Grid? I know it is possible with a table, but the Grid does not seem to respond to KeyPress event.

/Markus

marswe
28 Aug 2008, 4:14 AM
Are there any plans to implement KeyPress event on a Grid? This feature is already there on Table, would be helpful in order to be able to select a row in a Grid with pressing enter or similar.

Other features that would be good to have on a Grid is to disable sorting, column size changes and removal of columns.

Are there any plans for these features to be implemented?

/Markus

staffan
8 Sep 2008, 9:41 PM
What's the plans for Grid? Will the KeyPress event be supported?

I want to be able to select an item in my Grid and open a details screen corresponding to that item using the Enter key. Any way to do this?

staffan
12 Sep 2008, 4:29 AM
Please help me here. I want to start an action when pressing Enter-key in Grid. How do I do, Grid does not support KeyEvent (when using Table this was easy to do). What am I missing, why is this event not supported in Grid?

staffan
23 Sep 2008, 11:32 PM
Ok, I try to promot this one once more, because I've seen a lot Grid related questions, so hopefully someone knows this.

I want to fire a event from a Grid when pressing the Enter key (or any other key). When I used a table there was support for a KeyPress-Event but in Grid there is not. How do I do this?

gslender
24 Sep 2008, 1:56 AM
I'm guessing you'll need to sink key events - look into grid.el().addEventsSunk(Event.KEYEVENTS);

staffan
24 Sep 2008, 6:05 AM
I figured you meant something like this. I still can't get it to work though. Nothing happens when a press the Enter key. I tried to debug but it seams that the event is never fired.

I must admit that the .el().addEventSunk(..) is a little magic to me, but I understand it as this call will add the KeyPress event to my grid?

Maybe someone can help me fill in a little on the theory behind this, maybe getting it easier for me to get it to work..





searchResultGrid

.el().addEventsSunk(Events.KeyPress);

searchResultGrid.addListener(Events.KeyPress, new Listener<DomEvent>() {
publicvoid handleEvent(DomEvent e) {
if (e.getKeyCode() == KeyboardListener.KEY_ENTER) {
fireLoadEvent(sm.getSelectedItem());
}
}
});

staffan
25 Sep 2008, 2:22 AM
I've just got this solution from a friend, so if anyone has the same problem.

Make an instance of the KeyNav class for the target (in this case the Grid).
E.g like this:




KeyNav keyNav =

new KeyNav<ComponentEvent>(searchResultGrid) {

@Override

publicvoid onKeyPress(ComponentEvent ce) {
if (ce.getKeyCode() == KeyboardListener.KEY_ENTER) {
fireLoadEvent(sm.getSelectedItem());
}
}


};



Thanks Erik!