PDA

View Full Version : What's the proper way to iterate over columns of a grid ?



rixo
19 Oct 2012, 2:35 PM
Hi!

I was wondering about the cleanest way to access the columns of an Ext.grid.Panel in Ext4... I am asking here because I didn't find any clear public method or property in the doc. Of course, there is "columns", but that's a config option, not a public property and, in my mind, that's not safe to consider that as part of the API... Maybe I am wrong on this ?

In Ext3 there was a convoluted but clearly public way of doing this, using ColumnModel methods.

So, in Ext4, provided you only start with a reference to a grid panel, how do you iterate over its columns using only a safe public API ?

vietits
19 Oct 2012, 2:55 PM
You can use <grid>.headerCt.getGridColumns() (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.header.Container-method-getGridColumns) which returns an array of grid columns.

rixo
28 Oct 2012, 3:12 PM
Thanks for your answer, but headerCt is not documented public either (in fact, if the search in the doc is working properly, it is not documented at all). I could go with:


<grid>.getView().getHeaderCt()

But here again getHeaderCt() is documented private...

I guess I should stick with <grid>.columns which, at least, clearly conveys the intention (or, better, override Ext.panel.Table to add and expose getColumns() myself).

Animal
28 Oct 2012, 10:25 PM
getHeaderCt should be public.

rixo
29 Oct 2012, 3:08 AM
Probably, but I still don't feel that would be the best answer to my original question. That would not give an obvious way to access the columns, and the Column class represents more than just the header information (visibility, renderer, format, etc.). Furthermore a grid is not required to display a header...

Anyway, Animal, I appreciate that you're showing interest in the completeness of the documentation -- I was thinking maybe it was me being a bit of an extremist here.