View Full Version : Get selected row index number from Grid

22 Sep 2011, 5:19 PM
First off thanks for getting an already fantastic project updated to 2.2.5.

I am wanted to record the selected row # every time a row is selected in my grid. Now I have already setup a SelectionListener however I dont see anyway of getting the selected row number. I am getting the selected model from the row, and I see in the view it has a method of findRow(Element). Can someone please tell me what I would do to get the selected row? Do I need to give the findRow method the selectionmodel element or something?

Colin Alworth
23 Sep 2011, 1:39 PM
The Grid's GridSelectionModel will fire Events.SelectionChanged, which you should be receiving with a SelectionChangedListener. That listener gets a SelectionChangeEvent object passed to it, which contains the items in question.

The currently selected items can be used to get their index from the ListStore using store.indexOf.

Alternatively, you can listen to the Events.BeforeSelect fired from the selection model - there you will receive a SelectionEvent which already has the index of the item which what selected. Note that this selection might get canceled, so the other way is probably better.