Saturday, November 12, 2011

Date Sorting on Datagrid Column

For Sorting the Date timestamp column in datagrid you need to add the following changes in datagrid to the MXML file which contain timestamp value for EST timezone conversion .
The following code  is an example:-

Sorting on Date Column on Datagrid use the following code



<mx:DataGridColumn headerText="Timestamp" dataField="errorDateTime" width="200" sortCompareFunction="dateSortCompare"/>

Sorting is done by calling sortComapareFunction in Datagrid Column. Please follow method below for date sorting.

public static function dateSortCompare(date1:Object, date2:Object):int
{
var dateA:Date=DateFormatter.parseDateString(date1.errorDateTime);
var dateB:Date=DateFormatter.parseDateString(date2.errorDateTime);
//trace("date1.errorDateTime="+date1.errorDateTime+", date2.errorDateTime="+date2.errorDateTime+", "+ObjectUtil.dateCompare(dateA, dateB));
return ObjectUtil.dateCompare(dateA, dateB);
}

No comments:

Post a Comment