---
title: "Ext.grid.CheckboxSelectionModel 修复 checkbox bug"
author: "aviva"
date: "2009-12-24T15:35:03Z"
tags: []
categories: ["Web前端"]
slug: "ext-grid-checkboxselectionmodel-checkbox-bug"
draft: false
lastmod: "2009-12-24T17:04:12Z"
id: 555845
url: "https://aviva.iteye.com/blog/555845"
---

全选和取消选择的控制,扩展CheckboxSelectionModel即可, 对JS语法不太熟悉,琢磨了好久才完成.

**Merry Christmas!** 

if (Ext.grid.CheckboxSelectionModel) {  
 var interceptOnMouseDown = Ext.grid.CheckboxSelectionModel.prototype.onMouseDown.createInterceptor(function(e, t){  
   this.on('rowdeselect', this.handleDeselect, this);  
   this.on('rowselect', this.handleSelect, this);     
  }   
 );  
   
 Ext.override(Ext.grid.CheckboxSelectionModel, {  
  hd : null,       
    onMouseDown : interceptOnMouseDown,       
    handleSelect:function(){  
      if(this.grid.store.getCount()!=this.selections.length)  
    return;   
    var hd = Ext.fly(this.grid.getView().innerHd).child('div.x-grid3-hd-checker');  
      if(!hd.hasClass('x-grid3-hd-checker-on'))    
      hd.addClass('x-grid3-hd-checker-on');  
    },     
    handleDeselect:function(){  
      if( this.grid.store.getCount() != this.selections.length +1)  
    return;   
      var hd = Ext.fly(this.grid.getView().innerHd).child('div.x-grid3-hd-checker');   
      if(hd.hasClass('x-grid3-hd-checker-on'))  
       hd.removeClass('x-grid3-hd-checker-on');  
    }  
 });   
}