Adding selection listener to GXT Grid?
Asked Answered
P

5

5

I'm trying to add a selection listener to my GXT (Ext GWT) Grid, but I can't seem to get it to fire. I've tried many variations of this with no luck:

myGrid.addListener(Events.Select, new SelectionListener<ComponentEvent>() {

     @Override
     public void componentSelected(ComponentEvent ce) {
         System.out.println("selected");
     }
});
Plascencia answered 15/12, 2010 at 18:22 Comment(0)
S
11
        myGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<ModelData> se) {
            ...

        }
    });

Try this code

Svetlana answered 16/12, 2010 at 20:42 Comment(1)
Very useful answer. Note: this handler is fired even if unselection happens (Grid.getSelectionModel().addSelectionChangedHandler)Engraft
T
2

To upgrade this answer to GXT v3

grid.getSelectionModel().addSelectionChangedHandler(
  new SelectionChangedHandler<ModelData>(){

@Override
public void onSelectionChanged(SelectionChangedEvent<ModelData> event) {
    }
 });
Twilatwilight answered 25/2, 2013 at 23:13 Comment(0)
F
1

Try:

myGrid.addListener(Events.Select, new Listener<GridEvent<ModelData>>() {
    @Override public void handleEvent(GridEvent<ModelData> be) {
        System.out.println("selected");
    }
});

Replacing ModelData with your model type if necessary.

Foamflower answered 15/12, 2010 at 18:55 Comment(1)
It may be that your grid is not capturing the select event. When you replace Events.Select with Events.DoubleClick and doubleclick on a row does it work?Foamflower
P
1

Seemed to have found a workaround for this:

myGrid.addListener(Events.OnClick, new Listener<ComponentEvent>() {

    @Override
    public void handleEvent(ComponentEvent ce) {
        // Handle the grid event
    }
});

Seems like you just have to be generic about it, then you can check and cast your ComponentEvent to a GridEvent.

Plascencia answered 13/1, 2011 at 21:13 Comment(0)
M
0

Do you use GXT 2.x version ? Did you check whether required events are sinked? for example like grid.sinkEvents(Event.ONCLICK | Event.ONDBLCLICK | Event.MOUSEEVENTS);

Monitor answered 26/2, 2013 at 14:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.