1 Reply Latest reply on Sep 21, 2006 5:11 PM by savyasachi

    use sortcomparefunction

    trycold Level 1
      Hi,

      In my datagrid I have a date column. I used using labelfunction to have in a certain format. I am trying to use sortcomparefunction to sort on that column. I have tried using the following but it not working good. :

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

      private function SubmittedFucn(item:Object,column:DataGridColumn):String{
      var temp:String;
      temp = dateFormatter.format(item.DateStart);
      return(temp);}

      private function sortGrid(d1:Date, d2:Date):int {
      var result:int;
      var d1ms:Number = d1.getTime();
      var d2ms:Number = d2.getTime();

      if(d1ms > d2ms)
      {
      return -1;
      }
      else if(d1ms < d2ms)
      {
      return 1;
      }
      else
      {
      return 0;
      }
      }

      <mx:DataGridColumn dataField="DateStart" headerText="Started" labelFunction="SubmittedFucn" sortCompareFunction="sortGrid" />

      Thanks for your help.
        • 1. Re: use sortcomparefunction
          savyasachi Level 1
          trycold,

          In case if you have not solved this issue below yet. Here is the reason why your sortGrid() function is not working. The parameters for the sortGrid callback function are not of type Date type, it is actually getting the data element type that the data provider to the grid consists of.

          ex: if the dataprovider is an ArrayCollection of 'employee' type objects, you are getting the 'employee' objects as parameters representing the whole row in the grid (not just the DateStart column).