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).
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).
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.
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.
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);
}
}]
});
The following should work:
Ext.getCmp('simpsons').down('[dataIndex=ColumnName]').setVisible(false);
Get access to "your grid" and then
yourGrid.columnManager.getColumns()[index].setVisible(false);
If required do -- EXT 4
parent.doLayout();
EXT 6
parent.updateLayout();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With