1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Answers
    1
    Vote Rating
    0
    abc_da is on a distinguished road

      0  

    Default Answered: GXT Grid:BeforeSelect event, getSelectedItem

    Answered: GXT Grid:BeforeSelect event, getSelectedItem


    Hi,
    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.

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

  2. 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?

    Thanks.

  3. #2
    Sencha User
    Join Date
    Jun 2011
    Location
    Iasi, Romania
    Posts
    144
    Answers
    5
    Vote Rating
    0
    catalin.ciobanu is on a distinguished road

      0  

    Default


    you could have a static BaseModel which you change on "OnClick" ... and do whatever you want with it on "BeforeSelect"

    Have you tried this ?

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Answers
    1
    Vote Rating
    0
    abc_da is on a distinguished road

      0  

    Default


    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.

  5. #4
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Answers
    1
    Vote Rating
    0
    abc_da is on a distinguished road

      0  

    Default


    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?

    Thanks.

Thread Participants: 1

Tags for this Thread