Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort an ArrayCollection in Flex

I want to sort an Arraycollection by fieldName as ascending. Here's my code and I want to know whether it's right. Do you have any suggestions?

public static function arrayCollectionSort(ar:ArrayCollection, fieldName:String, isNumeric:Boolean):void 
    {var dataSortField:SortField = new SortField();
        dataSortField.name = fieldName;
        dataSortField.numeric = isNumeric;
        var numericDataSort:Sort = new Sort();
        numericDataSort.fields = [dataSortField];
        arrCol.sort = numericDataSort;
        arrCol.refresh();}
like image 373
Aravinth Avatar asked Feb 24 '12 10:02

Aravinth


1 Answers

The code you have is correct, except for a type. arrCol should be ar. The code looks almost exactly like the code at the blog Flex Examples, which is also correct.

Just change is change arrCol to ar like below:

public static function arrayCollectionSort(ar:ArrayCollection, fieldName:String, isNumeric:Boolean):void 
{
    var dataSortField:SortField = new SortField();
    dataSortField.name = fieldName;
    dataSortField.numeric = isNumeric;
    var numericDataSort:Sort = new Sort();
    numericDataSort.fields = [dataSortField];
    ar.sort = numericDataSort;
    ar.refresh();
}

Not sure with numeric but otherwise everything else is correct.

like image 104
Sagar Rawal Avatar answered Oct 15 '22 18:10

Sagar Rawal