Fill data from XML to AdvancedDataGrid
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:XMLList id="foodXML">
<menu label="Menu">
<amenu label="Breakfast">
<food label="A" price="$6.5" description="Option A"/>
<food label="B" name="name for B" price="$7.5" description="Option B"/>
</amenu>
<bmenu label="Lunch">
<food label="C" price="$8.5" description="Option C"/>
</bmenu>
</menu>
</mx:XMLList>
<mx:VBox width="400" height="300">
<mx:Script>
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
import mx.collections.HierarchicalData;
private function labelFunc(item:Object, column:AdvancedDataGridColumn):String
{
if(String(item.@label) != "") {
return String(item.@label);
}
return "";
}
</mx:Script>
<mx:AdvancedDataGrid dataProvider="{new HierarchicalData(foodXML)}" width="100%" height="100%">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" labelFunction="labelFunc"/>
<mx:AdvancedDataGridColumn dataField="@description"/>
<mx:AdvancedDataGridColumn dataField="@price"/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:VBox>
</mx:Application>
Related examples in the same category