PDA

View Full Version : Grid add columns dynamically



eztam
22 Mar 2010, 3:09 AM
Hi,

I wondered if it's possible to add columns to the grid dynamically?

My grid has to get an array with predefined columns to add.

For example I've got a custom Ext.grid.Column (with predefined id: 'customColumn') -> if I instantiate the grid like this:


var grid = new My.grid.GridPanel({
...
actions: ['customColumn'],
...
});

I want to add the column to the grid (the best would be if I could also define the position).
Is there no addColumn() function to handle this?


Thanks!

Condor
22 Mar 2010, 3:21 AM
See here (http://www.extjs.com/forum/showthread.php?t=53009).

eztam
22 Mar 2010, 7:03 AM
Thanks,

but I have no store field for the column.
This doesn't work correctly.

I tried some things and now my code is this:


Ext.override(Ext.grid.GridPanel, {
initComponent: Ext.grid.GridPanel.prototype.initComponent.createSequence(function() {
var col = new My.grid.Column();

// this function inserts the column to the defined index in colModel.config using colModel.setConfig function
this.colModel.insertColumn(col, 1);
})
});

This also doesn't work correctly, because the colModel.columns won't be updated.

This means the resulting colModel contains an array (length = 3) in columns index and an array (length = 4) in config index.

How do I update the colModel completely?

Condor
22 Mar 2010, 7:11 AM
The code I posted is for modifying the columns after the grid is rendered.

In initComponent the grid isn't rendered yet, so you could simply push() your columns in the specified columns array.