bug found. When event beforerowselect returns false the row is not selected, but the check marked as checked.
For create a work around this, I've overwrite the selectRow method to return boolean when the row has been selected:
Code:
selectRow : function(index, keepExisting, preventViewNotify){
if(this.fireEvent("beforerowselect", this, index, keepExisting, preventViewNotify) !== false){
Ext.grid.SmartCheckboxSelectionModel.superclass.selectRow.apply(this,[index, keepExisting, preventViewNotify]);
return true;
}else{
return false;
}
},
and modified the private function onMouseDown who's handle the click on the checkbox , handleMouseDown, selectRangeChecked
*Red mark where had change
onMouseDown
Code:
onMouseDown : function(e, t){
if(t.className && t.className.indexOf('x-grid3-cc-'+this.id) != -1){
e.stopEvent();
// Define variables
var view = this.grid.getView();
var rowIndex = view.findRowIndex(t);
var record = this.grid.store.getAt(rowIndex);
var isSelected = this.isSelected(rowIndex);
var isChecked = record.data[this.dataIndex];
// Logic to select/de-select rows and the checkboxes
if(!this.email || this.alwaysSelectOnCheck){
if (isSelected){
if(!isChecked && this.alwaysSelectOnCheck){
this.toggleChecked(rowIndex, true);
}
else{
this.deselectRow(rowIndex);
this.toggleChecked(rowIndex, false);
}
}
else{
if(this.selectRow(rowIndex, true)){
this.toggleChecked(rowIndex, true);
view.focusRow(rowIndex);
}
}
}
else{
if (isChecked){
this.toggleChecked(rowIndex, false);
}
else{
this.toggleChecked(rowIndex, true);
}
}
view.focusRow(rowIndex);
}
// Load the state manager
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
Ext.state.Manager.loaded = true;
},
handleMouseDown function
Code:
handleMouseDown : function(g, rowIndex, e){
var t = e.getTarget('.ux-row-action-item');
if(!t) {
if(e.button !== 0 || this.isLocked()){
return;
};
var view = this.grid.getView();
var record = this.grid.store.getAt(rowIndex);
if(e.shiftKey && this.last !== false){
var last = this.last;
this.selectRange(last, rowIndex, e.ctrlKey);
if(!this.email){ this.selectRangeChecked(last, rowIndex, e.ctrlKey); }
this.last = last; // reset the last
view.focusRow(rowIndex);
}else{
var isChecked = record.data[this.dataIndex];
var isSelected = this.isSelected(rowIndex);
if (isSelected){
this.deselectRow(rowIndex);
if(!this.email){ this.toggleChecked(rowIndex, false); }
}else{
if(!this.excel){
if(!this.email && this.selectRow(rowIndex, true)){
this.toggleChecked(rowIndex, true);
}
}
else{
if(!this.email && this.selectRow(rowIndex, e.ctrlKey)){
this.selectRangeChecked(rowIndex, rowIndex, e.ctrlKey);
}
}
view.focusRow(rowIndex);
}
}
}
}
selectRangeChecked
Code:
selectRangeChecked : function(startRow, endRow, keepExisting){
if(this.locked) return;
if(!keepExisting){
if(!this.email || this.alwaysSelectOnCheck){ this.clearSelections(); }
this.clearChecked();
}
if(startRow <= endRow){
for(var i = startRow; i <= endRow; i++){
if(this.grid.store.getAt(i)){
if(!this.email || this.alwaysSelectOnCheck){
if(this.selectRow(i, true)){
this.toggleChecked(i, true);
}
}else{
this.toggleChecked(i, true);
}
}
}
}
else{
for(var i = startRow; i >= endRow; i--){
if(this.grid.store.getAt(i)){
if(!this.email || this.alwaysSelectOnCheck){
if(this.selectRow(i, true)){
this.toggleChecked(i, true);
}
}else{
this.toggleChecked(i, true);
}
}
}
}
},
I tested the code, but NoahK17 try it a little more, I think there maybe some changes in the select with arrows.
Ops, I've forgot! I make some changes to your extension, can I?
if not, sorry.
Edit:
Sorry, one problem remain, when selected an row, the event beforerowselect occurs more than once. (I don't know how I will make the selectRow in Ext not execute.)