`

Ext CheckboxSelectionMode选中情况

 
阅读更多
在Ext的数据表中,有时我们会采用checkbox列来进行选中,有时确实是一个很好的体验,但是我不清楚从2.X到3.x一个BUG一直以来都没有修复,或者Ext认为这并不是一个BUG,那就是:当选中数据表时所有的记录时,数据表头上的那个一checkbox没有被选中,在做项目时遇到了这个问题,就给解决了,主要是对checkboxselectionmode进行了重写,代码如下所示:

Ext.override(Ext.grid.CheckboxSelectionModel,{
	onMouseDown : function(e, t){
        if(e.button === 0 && t.className == 'x-grid3-row-checker'){
            e.stopEvent();
            var row = e.getTarget('.x-grid3-row');
            if(row){
                var index = row.rowIndex;
                if(this.isSelected(index)){
                    this.deselectRow(index);
                }else{
                    this.selectRow(index, true);
                    this.grid.getView().focusRow(index);
                }
                
                /*检测数据表里的每一项是否都选中*/
                try{
                	var selectedNum = this.getCount();//取得选 中的记录数
                	var pageCont = this.grid.store.getCount();//取得当前一页共多少条记录
                	
					if(Ext.isEmpty(this.hdElement)){
						this.hdElement = Ext.select('div[class*=x-grid3-hd-inner x-grid3-hd-checker]',null,this.grid.id);
						this.hdEl = Ext.get(this.hdElement);
					}
					
					if(selectedNum == pageCont){
						this.hdEl.addClass('x-grid3-hd-checker-on');
					}else{
						this.hdEl.removeClass('x-grid3-hd-checker-on');
					}
                }catch(e){
                	//出现异常,不错处理
                }
                
            }
        }
    }
});


try{}catch(){}部分是我加入的代码
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics