View Full Version : How to iterate over the grid columns?

21 Aug 2012, 9:15 AM
Hi, guys! Who knows how to iterate over the grid columns. I need this method in order to get columns attributes (such as width, visibility - hidden or not). Now I use this method like this.

var columns = grid.headerCt.getVisibleGridColumns(false);

var fn = function (item, index, all)

//for ex. I get width attribute
colwidth = this.width;


Ext.each(grid.columns, fn);

But this method works only with "first-level" columns. If a grid has some grouped headers, the method does not iterate over sub-headers. Let me give you a concrete example. I have a grid like below and using this method I can get attributes of the "first-level" columns and can't reach attributes of subcolumns... Really need help. Many thanks!


21 Aug 2012, 9:20 AM
So, if there is an alternative or an extension of "Ext.each" method, that will do what is expected?

21 Aug 2012, 12:14 PM
I got it! This piece of code works fine.

var cls = grid.headerCt.getGridColumns();

var i = 0;

var ln = cls.length;


if(grid.headerCt.getHeaderAtIndex(i)) {

//for ex. I get width attribute

colwidth = grid.headerCt.getHeaderAtIndex(i).width;