<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.SortField;
import mx.collections.Sort;
private function sortByField(value:String,
isNumeric:Boolean = false,
isDescending:Boolean = false):Boolean {
var sortField:SortField = new SortField(value);
sortField.numeric = isNumeric;
sortField.descending = isDescending;
var sort:Sort = new Sort();
sort.fields = [sortField];
xmlListColl.sort = sort;
return xmlListColl.refresh();
}
]]>
</mx:Script>
<mx:XMLListCollection id="xmlListColl">
<mx:source>
<mx:XMLList>
<group name="Esthetique" value="2997" cost="0.52" />
<group name="xx" value="652" cost="0.47" />
<group name="xyt" value="652" cost="0.54" />
<group name="sss" value="652" cost="0.23" />
<group name="ffsdfsd" value="652" cost="0.82" />
</mx:XMLList>
</mx:source>
<mx:sort>
<mx:Sort>
<mx:SortField name="@cost"
numeric="true"
descending="true" />
</mx:Sort>
</mx:sort>
</mx:XMLListCollection>
<mx:Panel>
<mx:DataGrid dataProvider="{xmlListColl}" width="100%">
<mx:columns>
<mx:DataGridColumn dataField="@name" />
<mx:DataGridColumn dataField="@cost" />
<mx:DataGridColumn dataField="@value" />
</mx:columns>
</mx:DataGrid>
<mx:ControlBar>
<mx:Button label="Sort by @name"
click="sortByField('@name')" />
<mx:Button label="Sort by @cost"
click="sortByField('@cost', true, true);" />
<mx:Button label="Sort by @value"
click="sortByField('@value', true, true);" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>
Search This Blog
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment