Sort Collections
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.SortField;
import mx.collections.Sort;
import mx.collections.ArrayCollection;
[Bindable]
public var myCollection:ArrayCollection = new ArrayCollection
(
[
{label: "A"},
{label: "B"},
{label: "C"},
{label: "D"},
{label: "E"}
]
);
public function sortCollection():void
{
var sort:Sort = new Sort();
sort.fields = [new SortField("label", true, true)];
myCollection.sort = sort;
myCollection.refresh();
}
</mx:Script>
<mx:List dataProvider="{myCollection}" width="200" />
<mx:Button label="Sort Collection" click="sortCollection()" />
</mx:Application>
Related examples in the same category