views:

23

answers:

1

i used array collection sort method like below . but still sorting wrongly . Any other solution for sort date using flex3

public function SortingDate(ArrColl : ArrayCollection, field : String) : void{
            var sortA:Sort = new Sort();
            sortA.fields=[new SortField(field,false,true,null)];
            ArrColl.sort=sortA;
            ArrColl.refresh();
        }

it's sorting but day only sorting like

31/08/10
30/09/10
28/07/10
A: 

You need to specify a sortCompareFunction on the DataGridColumn you are using for dates.

It looks like this:

dateColumnSortCompareFunc(obj1:Object, obj2:Object) : int {
  // here you translate your object into things that can be evaluated
  // and return 1 if obj1 > obj2, 0 if they are equal, and -1 if obj1 < obj2
  // for example
  var d1:Date = new Date(obj1);
  var d2:Date = new Date(obj2);
  return ( d1.valueOf() > d2.valueOf() ) ? 1 : ( d1.valueOf() < d2.valueOf() ) ? -1 : 0;
}
Robusto
private function date_sortCompareFunc(itemA:Object, itemB:Object):int { var dateA:Date = new Date(Date.parse(itemA.enddatetime)); var dateB:Date = new Date(Date.parse(itemB.enddatetime)); return ObjectUtil.dateCompare(dateA, dateB); }
R.Vijayakumar
In above enddatetime is datafield in datagrid i used sortcompareFunction for compare (dd/mm/yy) format string but not sorting.could u certificate me
R.Vijayakumar
I use Date.valueOf() because it's simpler. Why convert it to a String first just to use Date.parse()? Date.valueOf() gives you milliseconds.
Robusto
i used Date.valueOf()also , but shows wrongly Mr.Robusto , Thank you for Response me
R.Vijayakumar
<mx:DataGridColumn headerText="Due Date" dataField="enddatetime" sortCompareFunction="dateColumnSortCompareFunc" /> i add ur function like this sortCompareFunction . enddatetime format is dd/mm/yy . is it right ?
R.Vijayakumar
In this case you need to put the function name in curly braces like so: `sortCompareFunction="{dateColumnSortCompareFunc}"` That way it gets treated as the object that it is.
Robusto