View Full Version : GXT Grid:BeforeSelect event, getSelectedItem

12 Oct 2011, 1:29 AM
could you please tell me, how to get the currently(prevoiusly) selected item in GXT Grid from within BeforeSelect event handler?

I have tried both selectionModel.getSelectedItem(); and but they both return null by the time BeforeSelect event reaches my listener.

public void handleEvent(SelectionEvent<ModelData> se) {
final GridSelectionModel<ModelData> selectionModel = (GridSelectionModel<ModelData>) se.getSource();
final int newSelectedIndex = se.getIndex();
final ModelData oldSelectedItem = selectionModel.getSelectedItem();

12 Oct 2011, 4:47 AM
you could have a static BaseModel which you change on "OnClick" ... and do whatever you want with it on "BeforeSelect"

Have you tried this ?

13 Oct 2011, 3:39 AM
catalin.ciobanu, thanks for your reply.
I'm sure, the solution you offered will work, but I thought there could be a better approach. As I figured out from the GridSelectionModel source code, the selected ModelData instance is stored in a private "lastSelected" field which is retrieved by getSelectedItem() getter method.

I just can't understand why the selection is cleared before the BeforeSelect event fires to my listener and is there a way to prevent such behaviour. This bahaviour results in loss of previous selection when the event is cancelled inside my BeforeSelect event listener.

13 Oct 2011, 11:27 PM
Ok, I figured it out.

It turnes out, I used the default SelectionMode.MULTI which leads to calling doDeselect prior to BeforeSelect event fires. SelectionMode.SINGLE has a different behaviour, calling to doDeselect after the BeforeSelect event fires so lastSelection becomes available to my listener.

Is it a bug or is it a feature? :)