ExtJs 4:如何动态隐藏/显示网格列? [英] ExtJs 4: How do I hide/show grid columns on the fly?

查看:108
本文介绍了ExtJs 4:如何动态隐藏/显示网格列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要即时显示/隐藏网格的列,但似乎ExtJs 4没有实现此目的的方法.

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

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

In previous versions I should use columnModel, what doesn't exist anymore.

仅获取grid.columns[index]hide()show()不会影响网格.

Just get grid.columns[index] and hide() or show() doesn't affect the grid.

使用grid.columnManaget.getColumns()[index].hide()可以真正隐藏该列,但无法再次显示(因为getColumns()之后不会返回该列).

Use grid.columnManaget.getColumns()[index].hide() can really hide the column, but it cannot be shown again (as getColumns() does not return that column after that).

推荐答案

以下方法应该起作用:

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

这篇关于ExtJs 4:如何动态隐藏/显示网格列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆