meej
15 Aug 2008, 1:48 PM
When using the Ext.grid.CheckboxSelectionModel class, the header checkbox may be selected to select all rows in the grid. However, if a row is deselected, the header checkbox remains selected, implying that all rows are still selected. The fix is trivial:
Ext.apply(Ext.grid.CheckboxSelectionModel.prototype, {
// enables simpleSelect behavior in CheckboxSelectionModel and fixes a bug
// wherein the header checkbox remains selected when rows are deselected
onMouseDown: function(e, t){
// if using left mouse button and simpleSelect or checkbox was clicked
if(e.button === 0 && (this.simpleSelect || 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);
// deselect checkbox header if selected
var hd = Ext.DomQuery.selectNode('.x-grid3-hd-checker', this.grid.view.innerHd);
if(hd) Ext.fly(hd).removeClass('x-grid3-hd-checker-on');
}else{
this.selectRow(index, true);
}
}
}
}
});
The above method also adds a feature to the CheckboxSelectionModel by enabling simpleSelect (as in DataView).
Ext.apply(Ext.grid.CheckboxSelectionModel.prototype, {
// enables simpleSelect behavior in CheckboxSelectionModel and fixes a bug
// wherein the header checkbox remains selected when rows are deselected
onMouseDown: function(e, t){
// if using left mouse button and simpleSelect or checkbox was clicked
if(e.button === 0 && (this.simpleSelect || 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);
// deselect checkbox header if selected
var hd = Ext.DomQuery.selectNode('.x-grid3-hd-checker', this.grid.view.innerHd);
if(hd) Ext.fly(hd).removeClass('x-grid3-hd-checker-on');
}else{
this.selectRow(index, true);
}
}
}
}
});
The above method also adds a feature to the CheckboxSelectionModel by enabling simpleSelect (as in DataView).