Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2279
  • Last Modified:

How to dynamically populate the Header Text of Flex Datagrid from XML

Hi,

I currently return an XML file (below) to Flex and have been assigning it to an array collection in order to populate a data grid.  This works fine.  The problem I have is that the headerText element for each datagrid column gets populated with the XML Attribute name (TEP_Lower).  As a result, I started returning a label version (TEP_Lower_Label) whose value I was hoping to dynamically assign to the hearderText.  My issue is that these element names (i.e., TEP_Lower_Label, TEP_Lower_Head_Label) will always be different so I needs it to be dynamic.  I tried putting this into an XML, XMLList, and/or XMLListCollection but I can't seem to loop through these elements.  Here are some of my attempts:


public var arrRawData:ArrayCollection = new ArrayCollection();      

__model.arrNewData = event.result.rawdata.record as ArrayCollection;
var xmlResult:XML = XML(event.result);

Any help would be greatly appreciated.

Thanks,
blue
<rawdata>
<record>
<RecordingDateTime>02/11/2009 11:31:00</RecordingDateTime>
<TEP_Lower>12.500 Hg</TEP_Lower>
<TEP_Lower_Label>TEP Lower Site</TEP_Lower_Label>
<TEP_Lower_Head>11.000 Hg</TEP_Lower_Head>
<TEP_Lower_Head_Label>TEP Lower Head Site</TEP_Lower_Head_Label>
</record>
<record>
<RecordingDateTime>02/10/2009 09:31:00</RecordingDateTime>
<TEP_Lower>11.500 Hg</TEP_Lower>
<TEP_Lower_Label>TEP Lower Site</TEP_Lower_Label>
<TEP_Lower_Head>9.500 Hg</TEP_Lower_Head>
<TEP_Lower_Head_Label>TEP Lower Head Site</TEP_Lower_Head_Label>
</record>
<record>
<RecordingDateTime>02/09/2009 09:31:00</RecordingDateTime>
<TEP_Lower>11.000 Hg</TEP_Lower>
<TEP_Lower_Label>TEP Lower Site</TEP_Lower_Label>
<TEP_Lower_Head>10.000 Hg</TEP_Lower_Head>
<TEP_Lower_Head_Label>TEP Lower Head Site</TEP_Lower_Head_Label>
</record>
<record>
<RecordingDateTime>02/06/2009 08:31:00</RecordingDateTime>
<TEP_Lower>12.500 Hg</TEP_Lower>
<TEP_Lower_Label>TEP Lower Site</TEP_Lower_Label>
<TEP_Lower_Head>10.000 Hg</TEP_Lower_Head>
<TEP_Lower_Head_Label>TEP Lower Head Site</TEP_Lower_Head_Label>
</record>
</rawdata>

Open in new window

0
blue44
Asked:
blue44
  • 3
  • 2
1 Solution
 
Jones911Commented:
Show the code for the dataGrid.
0
 
blue44Author Commented:
Here you go...

<mx:DataGrid id="dgData" width="100%" height="100%"
            variableRowHeight="true" wordWrap="true" dataProvider="{__model.arrRawData}"
            >                                                                        
      </mx:DataGrid>
0
 
Jones911Commented:
Ok in a data grid you can specify the column names and the data for the column:

 
<mx:DataGrid id="dgData" width="100%" height="100%"
            variableRowHeight="true" wordWrap="true" dataProvider="{__model.arrRawData}"
            >
		<mx:columns>
			<mx:DataGridColumn headerText="My Custom Label" dataField="TEP_Lower_Label" />
			
		</mx:columns>
	</mx:DataGrid>

Open in new window

0
 
blue44Author Commented:
I know you can specify DataGridColumns but that doesn't help me.  I don't want to hard code these column names.  I need these header texts to be variable -- that is, the headertexts need to change depending on what the Label Header that's returned in the XML record set (i.e., TEP_Lower_Head_Label).

I think looping around the record set, extracting the XML values and dynamically assigning them to the data grid columns is the way to go...I just don't know the syntax to do this.

Thanks
0
 
blue44Author Commented:
I never got a solution to this question and haven't been able to figure out a fix on my end either yet so please close this question as abandoned.  Thanks.
0

Featured Post

Put Machine Learning to Work--Protect Your Clients

Machine learning means Smarter Cybersecurity™ Solutions.
As technology continues to advance, managing and analyzing massive data sets just can’t be accomplished by humans alone. It requires huge amounts of memory and storage, as well as high-speed processing of the cloud.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now