PDA

View Full Version : need help on dynamic grid column configuration



evilight
29 Dec 2011, 2:21 AM
I'm n00b in ExtJS, it's a great framework which can save me a lot of time. :D
right now, I met a problem and have no idea how to solve, so I'm wondering if someone can get me some hints or sample code to solve my problem.

my problem is how to define grid's store/column/fields dynamically.
my app support user to input a date range, and I need to show the user result like following

Day1 | Day2 | Day3 | Day4
xx | yy | zz | xyz

for some reason (user requirement), I can't make it looks like this: (this will be easy, a 2 column grid will work)

Day1 | xx
Day2 | yy
Day3 | zz
Day4 | xyz

so, that's mean I have to define the model/fields/store dynamically
if people input a date range of 7 days, I need 7 columns, if people input a date range of 50 days, I need 50 columns.

I searched the forum, someone mentioned
reconfigure (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.panel.Table-method-reconfigure)( [Ext.data.Store (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store) store], [Object (http://docs.sencha.com/ext-js/4-0/#!/api/Object)[] columns] )

but I don't want to define 365 models/fields/stores, because user may input a date range of 1 year. (foolish input, but I have to handle)

and I also find someone mentioned

this.fields.add('FieldName',Ext.create('Ext.data.Field',{name:'FieldName', ...}));
so, I'm not sure if this also works on model/store?

or someone here can give an professional solution?

mitchellsimoens
29 Dec 2011, 9:24 AM
Your store just needs one date field. Then your columns you can create separate columns for each day of the span.

evilight
4 Jan 2012, 7:31 PM
thanks for your information, but maybe I don't make it more clear.
in fact, the column is not only date. it also have other fields like:

Category | percent | Day1 | Day2 | Day3 ......| Day30
aaa | 30% | A | B | A | X
bbb | 60% | A | A | A | N

so, if I only set one column. I think it still can not solve the problem..

is there any related sample available?