Sort on Multiple Fields in a Collection : Sort « Data Model « Flex

Home
Flex
1.Chart
2.Components
3.Container
4.Data Model
5.Development
6.Effects
7.Event
8.Graphics
9.Grid
10.Style
Flex » Data Model » Sort 




Sort on Multiple Fields in a Collection
Sort on Multiple Fields in a Collection
           
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:s="library://ns.adobe.com/flex/spark">
    
    <mx:ArrayCollection id="collection">
            <mx:source>
                <mx:Object name="A" dob="08/17/2010" />
                <mx:Object name="B" dob="07/30/2011" />
                <mx:Object name="C" dob="07/30/2012" />
                <mx:Object name="D" dob="07/30/2013" />
            </mx:source>
    </mx:ArrayCollection>
    
    <mx:Script>
        
            import mx.collections.Sort;
            import mx.utils.ObjectUtil;
            
            private function handleSort():void
            {
                var sort:Sort = new Sort();
                sort.compareFunction = sortFunction;
                collection.sort = sort;
                collection.refresh();
            }
            
            private function sortFunctiona:Object, b:Object, fields:Array = null ):Boolean
            {
                var dateA:Date = new DateDate.parsea.dob ) );
                var dateB:Date = new DateDate.parseb.dob ) );
                return ObjectUtil.dateComparedateA, dateB );
            }
      
    </mx:Script>
    
    
    <mx:DataGrid dataProvider="{collection}">
        <mx:columns>
            <mx:DataGridColumn dataField="name" />
            <mx:DataGridColumn dataField="dob" />
        </mx:columns>
    </mx:DataGrid>
    
    <mx:Button label="sort" click="handleSort();" />
    
</mx:Application>

   
    
    
    
    
    
    
    
    
    
    
  














Related examples in the same category
1.Use filter function and sortUse filter function and sort
2.Sort CollectionsSort Collections
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.