Use filter function and sort
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="600"> <mx:Script> import mx.collections.*; public function sortAC():void { var sortA:Sort = new Sort(); sortA.fields=[new SortField("label")]; myAC.sort=sortA; myAC.refresh(); } public function stateFilterFunc(item:Object):Boolean { return item.label >= "B" && item.label < "C"; } public function filterAC():void { myAC.filterFunction=stateFilterFunc; myAC.refresh(); } public function resetAC():void { myAC.filterFunction=null; myAC.sort=null; myAC.refresh(); } </mx:Script> <mx:ArrayCollection id="myAC"> <mx:Array id="myArray"> <mx:Object label="A" data="AA" /> <mx:Object label="B" data="BB" /> <mx:Object label="C" data="CC" /> </mx:Array> </mx:ArrayCollection> <mx:HBox width="100%"> <mx:Button id="sortButton" label="Sort" click="sortAC();" /> <mx:Button id="filterButton" label="Filter" click="filterAC();" /> <mx:Button id="resetButton" label="Reset" click="resetAC();" /> </mx:HBox> <mx:HBox width="100%"> <mx:ComboBox id="cb2" rowCount="10" dataProvider="{myArray}" /> <mx:ComboBox id="cb1" rowCount="10" dataProvider="{myAC}" /> </mx:HBox> </mx:Application>
1. | Sort Collections | ||
2. | Sort on Multiple Fields in a Collection |