-
1 Mar 2007 4:28 AM #1
Dynamic Columns for Grid
Dynamic Columns for Grid
Hi,
I am trying to render a grid the columns for which are user/server modifiable (stored as user preferences), hence i cannot have a column model like the one defined in the grid example. e.g.
Instead i have a xml that defines the column headers that i need to display. I create an array for each individual column config e.g.Code:var colModel = new YAHOO.ext.grid.DefaultColumnModel([ {header: "Author", width: 120, sortable: true}, {header: "Title", width: 180, sortable: true}, {header: "Manufacturer", width: 115, sortable: true}, {header: "Product Group", width: 100, sortable: true} ]);
However on doing so the rendereres are not activated, neither is the column header text visible. However the number of columns is being rendered right.Code:for(var l = 0; l < colHeaders.length; l++){ var tempCol; if(l == 0){ tempCol ='{header:"'+colHeaders[l].firstChild.nodeValue+'", width: 30}'; } else{ tempCol ='{header:"'+colHeaders[l].firstChild.nodeValue+'", width:150}'; } columnHeaders[l] = tempCol; } var colModel = new YAHOO.ext.grid.DefaultColumnModel(columnHeaders);
I would really appreciate if someone can point me in the right direction.
Thanks a lot!
-
1 Mar 2007 4:48 AM #2
You're creating an Array of strings, not an Array of column config objects.
-
1 Mar 2007 5:13 AM #3
Re: Dynamic Columns for Grid
Re: Dynamic Columns for Grid
I'm looking at doing exactly the same thing kinky_lizzard...
If you get it working, any chance you could post the code here
It would be very much appreciatedbe
-
1 Mar 2007 5:55 AM #4
Thanks Animal (Wonder y they call u that ) :roll:
i got it working with the following piece of code
Cheers!Code:var columnHeaders = new Array(); for(var l = 0; l < colHeaders.length; l++){ var columnConfig = new Object(); columnConfig.header = colHeaders[l].firstChild.nodeValue; if(l == 0){ columnConfig.width = 30; } else{ columnConfig.width = 150; } columnHeaders[l] = columnConfig; } var colModel = new YAHOO.ext.grid.DefaultColumnModel(columnHeaders);
-
1 Mar 2007 5:58 AM #5
or
(Growl!)Code:var columnHeaders = []; for(var l = 0; l < colHeaders.length; l++){ columnHeaders.push({width: (l == 0) ? 30 : 150, header: colHeaders[l].firstChild.nodeValue}); } var colModel = new YAHOO.ext.grid.DefaultColumnModel(columnHeaders);
-
1 Mar 2007 6:18 AM #6
on the same note how can i apply renderer on the columns:
attempts like
leads to the grid not being displayed at all, also the following alternative does not workCode:var columnHeaders = []; for(var l = 0; l < colHeaders.length; l++){ columnHeaders.push({width: (l == 0) ? 30 : 150, header: colHeaders[l].firstChild.nodeValue, renderer: imageRenderer}); } var colModel = new YAHOO.ext.grid.DefaultColumnModel(columnHeaders);
Enlighten me please!Code:var columnHeaders = []; for(var l = 0; l < colHeaders.length; l++){ columnHeaders.push({width: (l == 0) ? 30 : 150, header: colHeaders[l].firstChild.nodeValue}); } var colModel = new YAHOO.ext.grid.DefaultColumnModel(columnHeaders); colModel.setRenderer(0, imageRenderer);
-
1 Mar 2007 6:39 AM #7
Oops, mebbe i should look at the code more closely than shooting off my mouth. Lesson learnt.
Actually the renderer function has to be defined in the function that spans the grid, mine was not (it was defined inside an 'if' check)
Apologies :oops:
-
24 May 2010 11:20 PM #8
Can ths dynamic grid works with json reader?what are changes i have to make in my json reader and grid.
Thanks & regards
Similar Threads
-
Dynamic grid columns?
By SteveEisner in forum Ext 1.x: Help & DiscussionReplies: 35Last Post: 15 Jun 2012, 11:53 PM -
Max columns limitation in grid?
By jarrod in forum Ext 1.x: BugsReplies: 9Last Post: 26 Jun 2010, 4:52 AM -
Grid - Double Header Columns
By FuryVII in forum Ext 2.x: Help & DiscussionReplies: 0Last Post: 23 Feb 2007, 7:21 AM -
Nested Grid Columns
By dlibby00 in forum Community DiscussionReplies: 4Last Post: 29 Jan 2007, 9:53 AM


Reply With Quote