开发者

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 (-).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜