Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

extjs4

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 doesn't exist anymore.

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

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).

like image 303
paulodiovani Avatar asked Dec 26 '13 21:12

paulodiovani


People also ask

How to hide grid column in extjs?

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).

What is grid Extjs?

Grids are an excellent way of showing large amounts of tabular data on the client side. Essentially a supercharged <table> , Grid makes it easy to fetch, sort and filter large amounts of data. Grids are composed of two main pieces - a Ext. data. Store full of data and a set of columns to render.

How do I make the user select a single cell instead of an entire row in a grid in Extjs?

Single / Range cell selection. Column selection by click selecting column headers. Select / deselect all by clicking in the top-left, header. Adds row number column to enable row selection.


3 Answers

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);
        }
    }]
});
like image 103
third_eye Avatar answered Sep 27 '22 17:09

third_eye


The following should work:

Ext.getCmp('simpsons').down('[dataIndex=ColumnName]').setVisible(false);
like image 28
Naresh Kokkula Avatar answered Sep 27 '22 18:09

Naresh Kokkula


Get access to "your grid" and then

yourGrid.columnManager.getColumns()[index].setVisible(false);

If required do -- EXT 4

parent.doLayout();

EXT 6

parent.updateLayout();
like image 45
Pankaj Avhad Avatar answered Sep 27 '22 17:09

Pankaj Avhad