ExtJS4:如何动态隐藏/显示网格列?

ExtJS4:如何动态隐藏/显示网格列?,extjs4,Extjs4,我需要动态地显示/隐藏网格的列,但extjs4似乎没有实现这种方法 在以前的版本中,我应该使用columnModel,它不再存在 只需获取grid。列[index]和hide()或show()不会影响网格 使用grid.columnManaget.getColumns()[index].hide()确实可以隐藏该列,但它不能再次显示(因为getColumns()之后不会返回该列)。以下操作应该有效: Ext.create('Ext.grid.Panel', { title: 'Simps

我需要动态地显示/隐藏网格的列,但extjs4似乎没有实现这种方法

在以前的版本中,我应该使用columnModel,它不再存在

只需获取
grid。列[index]
hide()
show()
不会影响网格


使用
grid.columnManaget.getColumns()[index].hide()
确实可以隐藏该列,但它不能再次显示(因为
getColumns()
之后不会返回该列)。

以下操作应该有效:

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    id: 'simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody(),
    dockedItems:[{
        xtype:'button',
        handler: function() {
            if(Ext.getCmp('simpsons').columns[0].isVisible())
                Ext.getCmp('simpsons').columns[0].setVisible(false);
            else
                Ext.getCmp('simpsons').columns[0].setVisible(true);
        }
    }]
});
Ext.getCmp('simpsons').down('[dataIndex=ColumnName]').setVisible(false);

以下方面应起作用:

Ext.create('Ext.grid.Panel', {
    title: 'Simpsons',
    id: 'simpsons',
    store: Ext.data.StoreManager.lookup('simpsonsStore'),
    columns: [
        { text: 'Name',  dataIndex: 'name' },
        { text: 'Email', dataIndex: 'email', flex: 1 },
        { text: 'Phone', dataIndex: 'phone' }
    ],
    height: 200,
    width: 400,
    renderTo: Ext.getBody(),
    dockedItems:[{
        xtype:'button',
        handler: function() {
            if(Ext.getCmp('simpsons').columns[0].isVisible())
                Ext.getCmp('simpsons').columns[0].setVisible(false);
            else
                Ext.getCmp('simpsons').columns[0].setVisible(true);
        }
    }]
});
Ext.getCmp('simpsons').down('[dataIndex=ColumnName]').setVisible(false);
访问“您的网格”,然后

yourGrid.columnManager.getColumns()[index].setVisible(false);
如果需要,请执行-- 分机4

分机6

parent.updateLayout();

这对我有效

由于某种原因,这对我无效,因此我不得不使用
grid.columnManager.headerCt.items.get(0).setVisible(false)
我可以确认
grid.columns[n].setVisible(true | false)
在ExtJS4.2.1中工作