0 Replies Latest reply on Sep 24, 2010 6:28 AM by bindu84

    sorting

    bindu84

      I want to make multiple sort with date type sorting, i m able to multiple sort without date type soting. But with date type column i m not able to make multiple sort. Please help me how to do that

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <!-- http://flexonblog.wordpress.com/2009/11/16/sorting-dates-on-arraycollection-in-flex/ -->

      <mx:Application

       

      xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" initialize="init()">

       

       

      <mx:Script>

      <![CDATA[

       

      import mx.collections.SortField;

       

      import mx.controls.DateField;

       

      import mx.utils.ObjectUtil;

       

      import mx.collections.Sort;

       

      import mx.collections.ArrayCollection;

      [

      Bindable]

       

      private var arrClldetails:ArrayCollection = new ArrayCollection([

      {Fname:

      "Kranthi", Lname:"Kata", dob:"21/10/1979"},

      {Fname:

      "Vasanth", Lname:"Lola", dob:"12/01/1980"},

      {Fname:

      "Manoj", Lname:"Pati", dob:"16/09/1978"},

      {Fname:

      "John McClain", Lname:"Mela", dob:"15/01/1972"},

      ]);

       

      private function init():void

      {

       

      var sort:Sort=new Sort();

       

      //sort.compareFunction=fnCompareFunction;

       

      var sortByName:SortField = new SortField("Fname");

       

      //var sortByDate:SortField = new SortField("dob");

      sort.fields = [sortByName]

      arrClldetails.sort=sort;

      arrClldetails.refresh();

      }

       

      private function fnCompareFunction(ObjA:Object,ObjB:Object,fields:Array = null):int

      {

       

      var dateA:Date = new Date(Date.parse(ObjA.dob));

       

      var dateB:Date = new Date(Date.parse(ObjB.dob));

       

      return ObjectUtil.dateCompare(dateA, dateB);

       

      }

       

      ]]>

       

      </mx:Script>

       

      <mx:DateFormatter id="dateFormatter" formatString="DD/MM/YY"/>

       

      <mx:DataGrid id="dg" width="370" height="212" dataProvider="{arrClldetails}">

       

      <mx:columns>

       

      <mx:DataGridColumn headerText="First Name" dataField="Fname"/>

       

      <mx:DataGridColumn headerText="Last Name" dataField="Lname"/>

       

      <mx:DataGridColumn headerText="Date of Birth" dataField="dob"/>

       

      </mx:columns>

       

      </mx:DataGrid>

       

      </mx:Application>