Ext.grid.CheckColumn = function(config){
Ext.apply(this, config);
if(!this.globalId){
this.globalId = Ext.id();
}
this.renderer = this.renderer.createDelegate(this);
};
Ext.grid.CheckColumn.prototype ={
header : '<div class="x-grid3-hd-checker1"> </div>',
sortable : false,
menuDisabled : true,
fixed : true,
dataIndex : "checkColumn",
width:30,
init : function(grid){
this.grid = grid;
this.grid.on('render', function(){
var view = this.grid.getView();
view.mainBody.on('mousedown', this.onMouseDown, this);
Ext.fly(view.innerHd).on("mousedown", this.onHdMouseDown,this);
}, this);
},
onMouseDown : function(e, t){
if(t.className && t.className.indexOf('x-grid3-cc-'+this.globalId) != -1){
e.stopEvent();
var v=this.grid.getView();
var rowIndex = v.findRowIndex(t);
var columnIndex = v.findCellIndex(t);
var record = this.grid.store.getAt(rowIndex);
var value=false;
if(typeof(record.data[this.dataIndex]) != 'boolean'){
value=!(record.data[this.dataIndex]==2);
}else{
value=!record.data[this.dataIndex];
}
var ev = {
grid : this.grid,
record : record,
field : this.dataIndex,
originalValue : !value,
value : value,
row : rowIndex,
column : columnIndex,
cancel : false
};
if(this.grid.fireEvent('beforeedit',ev))
record.set(this.dataIndex, value);
else
return ;
this.grid.fireEvent('afteredit',ev);
}
},
selectAll : function(g) {
var d = this.grid.view;
var c = d.getRows();
for (var f = 0; f < c.length; f++) {
var b = this.grid.store.getAt(f);
b.data[this.dataIndex] = g;
var a = d.getCell(f, this.id);
var e = Ext.get(a).child("div.x-grid3-cc-" + this.globalId);
e.dom.className = this.getClassName(g);
}
},
onHdMouseDown : function(c, a) {
if (a.className == "x-grid3-hd-checker1") {
c.stopEvent();
var b = Ext.fly(a.parentNode);
var d = b.hasClass("x-grid3-hd-checker1-on");
if (d) {
b.removeClass("x-grid3-hd-checker1-on");
this.selectAll(false)
} else {
b.addClass("x-grid3-hd-checker1-on");
this.selectAll(true)
}
}
},
getClassName : function(a) {
return "x-grid3-check-col" + (a ? "-on" : "") + " x-grid3-cc-"
+ this.globalId;
},
renderer : function(v, p, record){
if(typeof(v) != 'boolean'){
v=v==2;
}
p.css += ' x-grid3-check-col-td';
return '<div class="'+this.getClassName(v)+'"> </div>';
}
};
Ext.reg('checkcolumn', Ext.grid.CheckColumn);//2代表true,其它值代表false
Ext.apply(this, config);
if(!this.globalId){
this.globalId = Ext.id();
}
this.renderer = this.renderer.createDelegate(this);
};
Ext.grid.CheckColumn.prototype ={
header : '<div class="x-grid3-hd-checker1"> </div>',
sortable : false,
menuDisabled : true,
fixed : true,
dataIndex : "checkColumn",
width:30,
init : function(grid){
this.grid = grid;
this.grid.on('render', function(){
var view = this.grid.getView();
view.mainBody.on('mousedown', this.onMouseDown, this);
Ext.fly(view.innerHd).on("mousedown", this.onHdMouseDown,this);
}, this);
},
onMouseDown : function(e, t){
if(t.className && t.className.indexOf('x-grid3-cc-'+this.globalId) != -1){
e.stopEvent();
var v=this.grid.getView();
var rowIndex = v.findRowIndex(t);
var columnIndex = v.findCellIndex(t);
var record = this.grid.store.getAt(rowIndex);
var value=false;
if(typeof(record.data[this.dataIndex]) != 'boolean'){
value=!(record.data[this.dataIndex]==2);
}else{
value=!record.data[this.dataIndex];
}
var ev = {
grid : this.grid,
record : record,
field : this.dataIndex,
originalValue : !value,
value : value,
row : rowIndex,
column : columnIndex,
cancel : false
};
if(this.grid.fireEvent('beforeedit',ev))
record.set(this.dataIndex, value);
else
return ;
this.grid.fireEvent('afteredit',ev);
}
},
selectAll : function(g) {
var d = this.grid.view;
var c = d.getRows();
for (var f = 0; f < c.length; f++) {
var b = this.grid.store.getAt(f);
b.data[this.dataIndex] = g;
var a = d.getCell(f, this.id);
var e = Ext.get(a).child("div.x-grid3-cc-" + this.globalId);
e.dom.className = this.getClassName(g);
}
},
onHdMouseDown : function(c, a) {
if (a.className == "x-grid3-hd-checker1") {
c.stopEvent();
var b = Ext.fly(a.parentNode);
var d = b.hasClass("x-grid3-hd-checker1-on");
if (d) {
b.removeClass("x-grid3-hd-checker1-on");
this.selectAll(false)
} else {
b.addClass("x-grid3-hd-checker1-on");
this.selectAll(true)
}
}
},
getClassName : function(a) {
return "x-grid3-check-col" + (a ? "-on" : "") + " x-grid3-cc-"
+ this.globalId;
},
renderer : function(v, p, record){
if(typeof(v) != 'boolean'){
v=v==2;
}
p.css += ' x-grid3-check-col-td';
return '<div class="'+this.getClassName(v)+'"> </div>';
}
};
Ext.reg('checkcolumn', Ext.grid.CheckColumn);//2代表true,其它值代表false