ExtJs 4: How do I hide/show grid columns on the fly?

前端 未结 4 1115
野的像风
野的像风 2021-01-02 17:46

I need to show/hide columns of a grid on the fly, but it seems that ExtJs 4 has no implemented method for that.

In previous versions I should use columnModel, what d

4条回答
  •  执念已碎
    2021-01-02 18:46

    The following should work:

    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);
            }
        }]
    });
    

提交回复
热议问题