[b] extjs的checkSelectionModel会在每一个grid数据前加一个勾选框,但是现在需求是管理员前面 没有勾选框,但是普通用户前面有勾选框,请问 这个勾选框怎么可以选择性的去掉。查了很多资料 ,据说勾选框只是个样式而已,只要将该样式去掉即可,求大家给点具体点的办法 ,最好是代码说明 :twisted: [/b]
用法很简单啊,上面发的是扩展后的CheckboxSelectionModel,你用它代替原有的就行了:
[code="js"]
var sm = new CustomCheckboxSelectionModel({
isSelectable : function(record){
return record.get("isAdmin") === true;
}
});
var grid = new Grid({
sm : sm,
columns : [sm]
});
[/code]
ext问题建议去问问 myali88 我感觉他都回答的比较好。就是答题高手排名的第六个。
你不把它放到columns就可以了,但这需要在创建grid时就知道它的权限:
[code="js"]
new Ext.grid.GridPanel({
sm : sm,
columns : [ /*sm, */, col1, col2, ... ]
});
[/code]
或者在运行中隐藏它:
[code="js"]
var colModel = grid.getColumnModel();
var colIndex = colModel.getIndexById("checker");
colModel.setHidden(colIndex, true);
[/code]
[code="js"]
var CustomCheckboxSelectionModel = Ext.extend(Ext.grid.CheckboxSelectionModel, {
isSelectable : function(record){ // 自行扩展
return true/false;
},
renderer : function(value, cellProperty, record){
if(this.isSelectable(record)){
return CustomCheckboxSelectionModel.superclass.renderer.apply(this, arguments);
}
return "";
},
selectRow : function(index){
var store = this.grid.store;
if(this.isSelectable(store.getAt(index))){
return CustomCheckboxSelectionModel.superclass.selectRow.apply(this, arguments);
}
}
});
[/code]