简体   繁体   English

如何在ExtJs4中动态设置网格CheckBox选择模型?

[英]How to dynamically set the grids CheckBox Selection Model in ExtJs4?

This leads on from my previous question . 这是从我之前的问题开始的
I initialize a grid with a CheckBox Selection Model, however when I reconfigure the grid the Check Box Selection Model visaully dissapears. 我使用CheckBox选择模型初始化网格,但是当我重新配置网格时,Checkbox选择模型完全消失了。
What I want to do is dynamically add a CheckBox Selection Model to a grid after reconfiguring the grids columns, and visually display it. 我想做的是在重新配置网格列之后动态地向网格添加一个CheckBox选择模型,并以可视方式显示它。

I have tried something like this: 我已经尝试过这样的事情:

var sm = new Ext.selection.CheckboxModel();
grid.selModel = sm;
grid.doLayout();

This worked for me. 这对我有用。 SelectionModel dynamic flag SelectionModel动态标志

//dynamically change, true or false, as the case 
selectionModel = true

var sm = {} // Selection Model

if (selectionModel){
    sm = Ext.create('Ext.selection.CheckboxModel')
}

var grid = Ext.create('Ext.grid.Panel', {
    selModel: sm,         
    frame: true,
    store: store,
    columns: columns,
    // more code ....
})

If you are using ExtJS4, just do a grid.getSelectionModel() after your reconfiguration and see if it works. 如果使用的是ExtJS4,只需在重新配置后执行grid.getSelectionModel() ,看看它是否有效。
You don't have to do anything with the returned value. 您无需对返回的值任何事情。 (if it doesn't work, debug to see what is returned by this method. is it an instance of CheckboxModel ?) (如果它不起作用,请调试以查看此方法返回的内容。它是否是CheckboxModel的实例?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM