0
votes

I am new to EXTJS. I have grid with a checkbox, and the checkbox will be checked or unchecked based on the boolean field in the model. I have this listener which does that when the store is loaded .Here is the following code.

listeners: {
    afterrender: function(obj)
       {                    
            var store = THIS.GridStore;
                var model = THIS.GridView.selModel;
            model.suspendEvents();
            store.load(
                {
            scope : this,
                params : {
                 method : 'getData',
                 eventId : 'nativemethodcall',
                 subEventId : ''
                  },
                 callback: function(records, operation, success)
                 {
                model.suspendEvents();
                    var count = store.getTotalCount();
                for (var i = 0; i < count; i++) {
                       var record = store.getAt(i);
                       if(record != undefined)
                        {
                        if (record.get('analyticsEnabled') == true) {
                                model.selectRange(i, i, true);
                                            }
                          }
                  }
                  model.resumeEvents();
              }
         });
     }
}

After the UI is rendered , I have listeners in checkbox selection model which will be called when the user checks or unchecks the checkbox and updates the model respectively. Code

selModel : Ext.create('Ext.selection.CheckboxModel',
                            {

                                listeners :
                                {

                                    deselect: function(model, record, index)
                                    alert('deselect called');
                                    {
                                        var store = THIS. GridStore;
                                        var record = store.getAt(index);
                                        record.set("Enabled", false);
                                        THIS.GridView.refresh();
                                    },
                                    select: function(model, record, index)
                                    {
                                    alert('select called');
                                        var store = THIS. GridStore;
                                        var record = store.getAt(index);
                                        record.set("Enabled", true);
                                        THIS.GridView.refresh();
                                    },
                                    selectionchange: function(model, selected, eOpts)
                                    {
                                        alert('selection called');
                                        var count = THIS. Store.getTotalCount();
                                        var selcount = selected.length;
                                        if (selcount == 0)
                                        {
                                            model.deselectAll(true);
                                            var store = THIS. GridStore;
                                            var count = store.getTotalCount();
                                            for (var i = 0; i < count; i++) {
                                                var record = store.getAt(i);
                                                if (record.get('Enabled') == true)
                                                {
                                                    record.set("Enabled", false);
                                                }
                                            }
                                            THIS.GridView.refresh();
                                        } else if (selcount == count)
                                        {
                                            model.selectAll(true);
                                            var store = THIS. GridStore;
                                            var count = store.getTotalCount();
                                            for (var i = 0; i < count; i++)
                                            {
                                                var record = store.getAt(i);
                                                if (record.get('Enabled') == false)
                                                {
                                                    record.set("Enabled", true);
                                                }
                                            }
                                            THIS. GridView.refresh();
                                        }

                                    }
                                }
                            }),

The problem I am facing is that, the selection checkbox model listeners(select & selection change ) function gets called when the call back functions checks the checkbox during the store load . I have suspended the model event like this var model = THIS.GridView.selModel; model.suspendEvents(); during the call back, but it doesn't seems to work .Please help.

1

1 Answers

0
votes

you can do it with using a checkColumn and cellModel, instead of using a checkboxSelection model.