Specify Sort Functions for DataGrid Columns
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
<mx:HTTPService id="srv" url="data.xml" resultFormat="object" result="onResult(event)"/>
<mx:DataGrid id="grid" width="100%" height="100%" dataProvider="{homesForSale}">
<mx:columns>
<mx:DataGridColumn headerText="Total No." dataField="total"/>
<mx:DataGridColumn headerText="Price Ranges [<350K] [350K -600K] [>600K]"
dataField="range"
sortCompareFunction="sortRanges"/>
</mx:columns>
</mx:DataGrid>
<mx:Script>
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var homesForSale:ArrayCollection;
private function initApp():void {
this.srv.send();
}
private function onResult(evt:ResultEvent):void {
this.homesForSale = evt.result.data.region;
}
private function sortRanges(obj1:Object, obj2:Object):int{
var value1:Number = obj1.range.range1;
var value2:Number = obj2.range.range1;
if(value1 < value2) {
return -1;
}
else if(value1 > value2){
return 1;
}
else {
return 0;
}
}
</mx:Script>
</mx:Application>
Related examples in the same category