Search code examples
extjsgxt

Sencha GXT 3.0 how to capture grid checkbox deselection


All I want to do is capture an event every time an item in a Grid using CheckBoxSelectionModel is either checked or unchecked. The checked/selected part is easy using the SelectionHandler. I'm not seeing anything that fires a deselection event in a multi-select mode though. I have a grid with 1000 items or so, and I let users multi-select items to track on a map. It's not giong to perform well to scan the entire model whenever a selection changes so I'm wondering how to handle this.


Solution

  • You are correct. SelectionHandler will only provide checked/selected status. I had a similar requirement and I solved it by overriding the onSelectChange() method of CheckBoxSelectionModel.

    Here is the sample code for your reference.

    IdentityValueProvider<VO> identity = new IdentityValueProvider<VO>();
    CheckBoxSelectionModel<VO> sm = new CheckBoxSelectionModel<VO>(identity) {
    
        protected void onSelectChange(VO model, boolean select) {
    
            super.onSelectChange(model, select);
            if (select) {
                // Do something on select ...
            } else {
                // Do something on deselect ...
            }
        };
    };
    

    Hope this helps.