Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding selection listener to GXT Grid?

Tags:

java

grid

gwt

gxt

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");
     }
});
like image 603
thedude19 Avatar asked Dec 15 '10 18:12

thedude19


4 Answers

        myGrid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

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

        }
    });

Try this code

like image 58
Xi CHEN Avatar answered Oct 06 '22 07:10

Xi CHEN


To upgrade this answer to GXT v3

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

@Override
public void onSelectionChanged(SelectionChangedEvent<ModelData> event) {
    }
 });
like image 33
Stevko Avatar answered Oct 06 '22 07:10

Stevko


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.

like image 25
Abdullah Jibaly Avatar answered Oct 06 '22 06:10

Abdullah Jibaly


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.

like image 20
thedude19 Avatar answered Oct 06 '22 06:10

thedude19