2 Replies Latest reply on Sep 27, 2010 9:27 PM by bindu84


    bindu84 Level 1

      i want t o do multicolumn sort, at the time of initilixation of data grid

      where one column is type of  one is type of  Alphanumeric, one is type of date type.



      How to do that , i have attached some code but it is not working



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

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




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






      import mx.collections.SortField;


      import mx.controls.DateField;


      import mx.utils.ObjectUtil;


      import mx.collections.Sort;


      import mx.collections.ArrayCollection;




      private var arrClldetails:ArrayCollection = new ArrayCollection([


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


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


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


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



      private function init():void



      var sort:Sort=new Sort();



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


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

      sort.fields = [sortByDate,sortByName]










      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:DateFormatter id="dateFormatter" formatString="DD/MM/YY"/>


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




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


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


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







        • 1. Re: sorting
          jfb00 Level 3


          Try this:

                     private function init():void
                          var sort:Sort=new Sort();
                          var sortByName:SortField = new SortField();
                          sortByName.name = "Fname";
                          var sortByDate:SortField = new SortField();
                          sortByDate.name = "dob";
                          sortByDate.compareFunction = fnCompareFunction;
                          sort.fields = [sortByDate,sortByName]



          Please rate my answer. Tks!

          • 2. Re: sorting
            bindu84 Level 1

            Thanx a lot