Creating a datasource to display the grid, where the number of columns varies

Hi Isomorphic,

I have a requirement where in the number of columns displayed in the grid are dynamic. How to write a datasource, where the number of columns displayed varies dynamically from 1 to 5.

On the screen the grid looks like:

		Scenario 1	Scenario 2	.	.	Scenario 5
Volume	
Product
Price
Vendor
.
.
.
.
Profit

While retrieving the data from database the resultset is like:

Scenario       Volume  Product  Price  Vendor	    ……	Profit	
Scenario 1	123	123	123	A		12
Scenario 2	234	234	234	B	   	23
.
.
Scenario 5	689	689	689	N		56

If I modify the data after getting it from the result set in such a way that I can display it in listgrid then, how to write a datasource with varying fields dynamically.
If I fetch the data as it is from the result set to display it in cubegrid then, how to write the varying values array for column facets.

For either ListGrid or CubeGrid usage, you can just use JavaScript to generate field definitions or facet value definitions respectively. field and facetValue definitions are just JavaScript Objects, just like the Array of JavaScript Objects returned by DataSource.fetchData().

Hi Isomorphic,

Thanks for the reply.

Could you please elaborate your explanation a bit more.

What ever i have worked is… I will write a datasource with operation bindings… All the <field> tags have an attribute called “title”… when i specify some value to title then that will be displayed as Column header in my listgrid…

Here i am specifying what should be my column header. Its more like i am hardcoding. But now the value is coming from database. So i can not hardcode it? And in datasource if i have 5 field tags then 5 columns will be displayed in the grid. But now i dont have the luxury to specify the number of fixed fields in the datasource. It also varies dynamically.

Thanks
Strive

See the docs for creating dataSources. DataSources can be created in JavaScript on the fly.