Flex Advance datagrid date column sorting problem
I'm trying to sort ArrayCollection
with following dates, and getting unexpected results.
14-Apr-1980
01-Feb-1975
30-Dec-1977
27-Oct-1968
I'm using following code to sort,
private function sortDate(obj1:Object, obj2:Object):int
{
var d1:Number = (new Date(Date.parse(obj1.date))).getTime();
var d2:Number = (new Date(Date.parse(obj2.date))).getTime();
if(d1 < d2)
{
return -1;
}
else if(d1 == d2)
{
return 0;
}
return 1;
}
And it's called like ,
<mx:AdvancedDataGridColumn dataField="dob"
headerText="Date of birth:"
sortCompareFunction="sortDate"
dataTipFunction="dateFormat" />
</mx:columns>
Results are coming like ,
27-Oct-1968
01-Feb-1975
14-Apr-1980
30-Dec-1977
What am I missing ?
(Note : my date format in AdvancedDataGrid
is DD-MMM-YYYY
)
Change the date separator from hyphen (-
) to a slash (/
) or a space
. And make sure that the sortableColumns
property of AdvancedDataGrid
is true
From the livedocs page for Date.parse()
method.
The year month and day terms can be separated by a forward slash (
/
) or by spaces, but never by a dash (-
).
精彩评论