Thanks,
Made a couple of modifications based on your example and got it to 
work.

Here is the function for the record (headers String and Alert 
commented out):

public function updateGridData():void{
   var newColumns:Array = new Array();
   //var headers:String = new String();

   var i:int;
   for (i = 0; i<columnData.length; i++) {
      var column:DataGridColumn = new DataGridColumn();
      column.dataField = columnData[i].name; 
      column.headerText = getheaderText(columnData[i]);  
      //headers = headers + column.headerText + ", ";
      newColumns.push(column);
   }

   dGrid.dataProvider = gridData;
   dGrid.columns = newColumns; 

   //mx.controls.Alert.show("Updated the DataGrid.  Headers SHOULD   
be: " + headers);
}

--- In flexcoders@yahoogroups.com, "Sebastian Zarzycki" <[EMAIL PROTECTED]> 
wrote:
>
> But what result you get? Make sure that data are already there 
(gridData and
> columnData are filled with values) when you launch this method.
> I would fix the code with the following :
> 
> var headers:String = new String();
> var newColumns:Array = new Array();
> 
> // flex loops are generally done this way (see
> 
http://livedocs.adobe.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhel
p.htm?
> context=LiveDocs_Parts&file=00001831.html)                    
        
> var i:int;
> for (i = 0; i<columnData.length; i++) {
>     var column:DataGridColumn = new DataGridColumn(columnData
[i].name);
>     column.dataField = columnData[i].name; // there wasn't [i] 
index here
>     column.headerText = getheaderText(columnData[i]); // aren't you 
setting
> name/header in constructor?
>     //headers = headers + getheaderText(columnData[i]) + ", "; // 
what is
> this for?
>     newColumns.push(column);
> }
> 
> dGrid.dataProvider = gridData;
> dGrid.columns = newColumns; // it's better to assign at the end, to 
avoid
> datagrid invalidations on every column added.
> 
> 
> 
> 
> -----Original Message-----
> From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> Behalf Of Dominic Pazula
> Sent: Monday, January 21, 2008 9:04 PM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Dynamically Generating Column Attributes for 
a Data
> Grid
> 
> I tried to search for this but got a "server busy" error.  I 
figured 
> I would go ahead and post it.  I appologize if this has been 
covered 
> before.
> 
> I'm trying to dynamically generate columns for my datagrid.  I 
don't 
> have prior knowledge of the column attributes before receiving the 
> data.  I get two ArrayCollection objects, one with the data 
(gridData)
> and one with the metadata about the columns (called columnData from 
> here on).
> 
> Here is the function I am trying to write:
> public function updateGridData():void{
> var column:DataGridColumn;
> var headers:String = new String();
>                               
> for (var i:int =0; i<columnData.length; i++){
>     column  = new DataGridColumn(columnData[i].name);
>     //column.dataField = columnData.name;
>     column.headerText = getheaderText(columnData[i]);
>     //headers = headers + getheaderText(columnData[i]) + ", ";
>     dGrid.columns.push(column);
> }
> dGrid.dataProvider = gridData;
> //mx.controls.Alert.show("Updated the DataGrid.  Headers SHOULD 
be: " 
> + headers);
> }
> 
> The "getheaderText()" function returns the header text value based 
on 
> a user selection (description or name).
> 
> What am I doing wrong here?
> 
> Thanks
> Dominic
> 
> 
> 
> --
> Flexcoders Mailing List
> FAQ: 
http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%
40yahoogroups.com 
> Yahoo! Groups Links
>


Reply via email to