Tuesday, 10 September 2013

Group a datafield to AdvancedDatagrid from PHP output data

Group a datafield to AdvancedDatagrid from PHP output data

I had my PHP output into XML tag format and I wanted to group the
datafield='brname' as the main tree or group in my AdvancedDatagrid.
<html>
<head></head>
<body>
<show>
<show_list>
<brname>HONDA</brname>
<dscrpn>CIVIC 2DR</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>GUAM</cr_loc>
<cr_ave>1.33</cr_ave>
</show_list>
<show_list>
<brname>HONDA</brname>
<dscrpn>FIT</dscrpn>
<cr_mdl></cr_mdl>
<cr_loc>SAIPAN</cr_loc>
<cr_ave>1.5</cr_ave>
</show_list>
</show>
</body>
</html>
I have the HTTPService to get the data from the PHP output as:
<s:HTTPService id="link" url="the php address..." method="GET"/>
I found a sample of the AdvancedDatagrid, however, the data is declared
into an Arraycollection which is not applicable to me.
http://kirill-poletaev.blogspot.com/2011/07/advanceddatagrid-in-flex-part-3.html
I tried to do the similar code and just change the DataProvider just to
test the concept if it can be applied to my desired output.
private function init():void{
var myGC:GroupingCollection2 = new GroupingCollection2();
var myG:Grouping = new Grouping();
var myGF:GroupingField = new GroupingField();
myGF.name = "dscrpn";
myG.fields = [myGF];
myGC.grouping = myG;
myGC.source = myGrid.dataProvider;
myGC.refresh();
myGrid.dataProvider = myGC;
}
<mx:AdvancedDataGrid sortExpertMode="true"
dataProvider="{link.lastResult.show.show_list}" creationComplete="init()"
id="myGrid">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="brname" headerText="Brand" />
<mx:AdvancedDataGridColumn dataField="dscrpn"
headerText="Description" />
<mx:AdvancedDataGridColumn dataField="cr_mdl" headerText="Mdel"/>
<mx:AdvancedDataGridColumn dataField="cr_loc" headerText="Loc"/>
<mx:AdvancedDataGridColumn dataField="cr_ave" headerText="Average"/>
</mx:columns>
</mx:AdvancedDataGrid>
Here is the output of my code 1
Sorry I am a bit new in using AdvancedDatagrid View. Thank You.

No comments:

Post a Comment