20090703

Sorting an ArrayCollection



public function sortCollection(arrayCollection : ArrayCollection) : void
{
//Create the sort field
var dataSortField:SortField = new SortField();

//name of the field of the object on which you wish to sort the Collection
dataSortField.name = "name";
dataSortField.caseInsensitive = true;

/*
If you wish to perform numeric sort then set:
dataSortField.numeric = true;
*/

//create the sort object
var dataSort:Sort = new Sort();
dataSort.fields = [dataSortField];

arrayCollection.sort = dataSort;
//refresh the collection to sort
arrayCollection.refresh();

}


3 comments:

Jean Ayoub said...

Hi Bhuvan,

Kreeda Games is India's leading MMOG Publisher & Game Developer & we work closely with companies like Electronic Arts & Rockstar Games.We are funded by two of the top venture capitalist companies in Gaming- IDG Ventures & Soft Bank.
Kreeda is currently one of the few companies in India working on projects for virtual world game development. This should give any ambitious Flash Programmer opportunity to use their skills on the most advanced technologies like AS3 and game engines like EUP and Smartfox.

Kreeda's management consists of three ex-IBMers. Kreeda is currently hiring for senior position to lead the development of Virtual Worlds, Games & Social Networking Websites.

I came across your blog and wanted to discuss an exciting project that might interest & challenge you.
Feel free to drop me an email at aparna@kreeda.com

Aparna Majumdar

P.S- Apologies for using your comment board to initiate correspondence with you.

Unknown said...

thank you !

that's was usefull to me !

i am learning Flex3...

Kuriakose Jacob Thomas said...

http://kuriakosejacobthomas.blogspot.com/2009/10/adobe-flex-sorting-arraycolleciton-by.html

Adobe Flex - Sorting an ArrayColleciton by Date
/**
* @params data:Array
* @return dataCollection:Array
**/
private function orderByPeriod(data:Array):Array
{
var dataCollection:ArrayCollection = new ArrayCollection(data);//Convert Array to ArrayCollection to perform sort function

var dataSortField:SortField = new SortField();
dataSortField.name = "period"; //Assign the sort field to the field that holds the date string

var numericDataSort:Sort = new Sort();
numericDataSort.fields = [dataSortField];
dataCollection.sort = numericDataSort;
dataCollection.refresh();
return dataCollection.toArray();
}