ExtJs4 - What is the equivalent to the grid ColumnModel?

旧巷老猫 提交于 2019-12-01 00:48:33

问题


What is the equivalent to the ExtJs3 Ext.grid.ColumnModel in ExtJs4?

What I want to do is hide a column, I did something like below in ExtJs3:

grid.colModel.setHidden(1, true);

回答1:


You can hide/show column using setVisible method of Ext.grid.column.Column:

grid.columns[1].setVisible(false);



回答2:


The other answers can be problematic if your column indexes change.

Here is another solution:

Set itemId on the column definition:

{
        itemId: 'myActionColumn',
        xtype: 'actioncolumn',
        width: 50,
        items: [ ...
}

Then to hide:

grid.down('#myActionColumn').hide();



回答3:


Ext.grid.header.Container

code of Ext.panel.Table:

 headerCtCfg = me.columns || me.colModel, 
 ...
if (headerCtCfg instanceof Ext.grid.header.Container) {
            me.headerCt = headerCtCfg;
            me.headerCt.border = border;
            me.columns = me.headerCt.items.items;
}

so u can use

grid.columns[i].hide()/show()



回答4:


Another solution more flexible :

grid.down("[dataIndex="+di+"]").setVisible(v);

You can change dataIndex for another property like name or whatever.



来源:https://stackoverflow.com/questions/6042138/extjs4-what-is-the-equivalent-to-the-grid-columnmodel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!