Sort Arraycollection based on date field in Flex

If you have ArrayCollection as Dataprovider to Datagrid and you want to sort dataprovider based on single date field for ex: created_Date or modified_Date, then below is code snippet:

public function sortOnFilterModifiedDate():void
var dataSortField:SortField = new SortField(); = “modified_Date”;//date field
dataSortField.numeric = false;
dataSortField.descending = true;//true or false do not affect sorting logic
dataSortField.caseInsensitive = true;

var filterModifiedDateSort:Sort = new Sort();
filterModifiedDateSort.fields = [dataSortField];
filterModifiedDateSort.compareFunction = filterModifiedDateSortCompareFunc;

pageFilters.sort = filterModifiedDateSort;


private function filterModifiedDateSortCompareFunc (itemA:Object,itemB:Object,fields:Array):int
return ObjectUtil.dateCompare(DateFormatter.parseDateString(itemA.modified_Date),


Use below code to sort in Descending order: -1*ObjectUtil.dateCompare(DateFormatter.parseDateString(itemA.modified_Date),




  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: