此问题和解决方法为ExtJs2.2中遇到的问题,其它版本慎用!
第一种解决办法,禁止行选中事件:
在创建sm实例的时候加一个参数就可以了
var sm = Ext.grid.CheckboxSelectionModel({handleMouseDown: Ext.emptyFn})
var sm = Ext.grid.CheckboxSelectionModel({handleMouseDown: Ext.emptyFn})
这样处理之后,必须勾选checkbox才能进行行选择,点击行其它位置,没有任何反应。
第二种解决办法,重写
CheckboxSelectionModel的
handleMouseDown事件
this
._selections =
new
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);
}
}
}
});
这样,行选中和checkbox选中,均能选中行,达到了统一的效果。
转载于:https://blog.51cto.com/wangyuelucky/1186372