1.ext 中checkbox 在选中几个记录时,在单击选中的一行记录,其他选中行会消失的问题,及全选框该不该选中的问题,将下面代码复制到项目中(可能会出现点击gridpanel 的行的时候,无法选中的问题,请看描述2)
Ext.override(Ext.grid.RowSelectionModel, {
selectRow : function(B, D, A) {
if(this.singleSelect==false){
if (this.locked || (B < 0 || B >= this.grid.store.getCount())
|| this.isSelected(B)) {
return;
}
var C = this.grid.store.getAt(B);
if (this.fireEvent("beforerowselect", this, B, D, C) !== false) {
if (!D) {
this.selections.remove(C);
} else {
this.selections.add(C);
this.last = this.lastActive = B;
}
if (D) {
this.grid.getView().onRowSelect(B);
}
this.fireEvent("rowselect", this, B, C);
this.fireEvent("selectionchange", this)
}
}else{
if(this.locked || (B < 0 || B >= this.grid.store.getCount()) || this.isSelected(B)) return;
var r = this.grid.store.getAt(B);
if(r && this.fireEvent("beforerowselect", this, B, D, r) !== false){
if(!D || this.singleSelect){
this.clearSelections();
}
this.selections.add(r);
this.last = this.lastActive = B;
if(!A){
this.grid.getView().onRowSelect(B);
}
this.fireEvent("rowselect", this, B, r);
this.fireEvent("selectionchange", this);
}
}
}
,
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 {
this.selectRow(rowIndex, true);
view.focusRow(rowIndex);
}
}
}
});
2.解决 添加了 问题 1 的 代码,gridpanel 中点击行无法获得选中值的问题
//具体事件名称可以根据需要自己写, 这里只是提供一个思路, 这里实现的是 点击一行(该行有点击事件,只能监听你 该行用renderer 赋值的列)
Ext.override(Ext.grid.GridPanel,{
listeners:{
cellmousedown:function (grid,rowIndex,columnIndex,e){
var selectm=grid.getSelectionModel();
selectm.clearSelections();
selectm.selectRow(rowIndex, true);
}
}
});