ExtJS CheckboxSelectionModel header deselect on reload

Today, I discovered that the CheckboxSelectionModel does not clean up after itself on a store reload. If you previously used the header checkbox that selects all records, if you reload the store for whatever reason — I reconfigure my grid with a new store all the time — the header is left checked.

I found a relatively easy solution after playing around with various selection models last night.

myGrid = Ext.extend(Ext.grid.GridPanel, {
  initComponent:function() {
  /// ... configure store, ect
  myGrid.superclass.initComponent.apply(this, arguments);
 
  this.getStore().on('load', function() {
    var hd = Ext.fly(this.getView().innerHd).child('.x-grid3-hd-checker-on');
    if(hd) {
      hd.removeClass('x-grid3-hd-checker-on');
    }
  }
}

On a store load event, if the header of the grid with the checkbox is checked, based upon the class above, I simply remove it. All is well.

My grid is somewhat more complicated than that, mostly because I add a new store during a reconfigure, necessitating that I add that listener on the new store everytime I add one, not in initComponent. If you never swap the store, the above is fine.

Post a Comment

Your email is never shared. Required fields are marked *

*
*