当前位置: 代码迷 >> Web前端 >> grid checkbox 多选有关问题. (更改为 点击条目 实现多选 )
  详细解决方案

grid checkbox 多选有关问题. (更改为 点击条目 实现多选 )

热度:363   发布时间:2012-10-13 11:38:17.0
grid checkbox 多选问题.. (更改为 点击条目 实现多选 )
1. 覆盖原方法
Ext.override(Ext.grid.CheckboxSelectionModel, {
		handleMouseDown : function(g, rowIndex, e) {
			if (e.button !== 0 || this.isLocked()) {
				return;
			}
			var view = this.grid.getView();
			if (e.shiftKey && !this.singleSelect && this.last !== false) {
				var last = this.last;
				this.selectRange(last, rowIndex, e.ctrlKey);
				this.last = last; // reset the last
				view.focusRow(rowIndex);
			} else {
				var isSelected = this.isSelected(rowIndex);
				if (isSelected) {
					this.deselectRow(rowIndex);
				} else if (!isSelected || this.getCount() > 1) {
					this.selectRow(rowIndex, true);
					view.focusRow(rowIndex);
				}
			}
		}
	});


2. 使用创建 子对象的方式 :  (不会影响 原来的定义)
Ext.namespace('Ext.xz');     
	      
	Ext.xz.CheckboxSelectionModel =function(config)     
	{     
	    Ext.xz.CheckboxSelectionModel.superclass.constructor.call(this,config);     
	    this.group = config.group;     
	    this.value=config.value;     
	};     
	
	// 实现点击内容可多选
	Ext.extend(Ext.xz.CheckboxSelectionModel, Ext.grid.CheckboxSelectionModel,{
		handleMouseDown : function(g, rowIndex, e) {
			if (e.button !== 0 || this.isLocked()) {
				return;
			}
			var view = this.grid.getView();
			if (e.shiftKey && !this.singleSelect && this.last !== false) {
				var last = this.last;
				this.selectRange(last, rowIndex, e.ctrlKey);
				this.last = last; // reset the last
				view.focusRow(rowIndex);
			} else {
				var isSelected = this.isSelected(rowIndex);
				if (isSelected) {
					this.deselectRow(rowIndex);
				} else if (!isSelected || this.getCount() > 1) {
					this.selectRow(rowIndex, true);
					view.focusRow(rowIndex);
				}
			}
		}
	});

  相关解决方案