ArrayCollection
is a subclass of ListCollectionView
that has a sort
property. The Sort
class has a compareFunction
property that you can use to define custom sort functions.
private function sortFunction(a:Object, b:Object, array:Array = null):void
{
//assuming that 'level' is the name of the variable in each object
//that holds values like "Critical", "High" etc
var levels:Array = ["Low", "Medium", "High", "Critical"];
var aLevel:Number = levels.indexOf(a.level);
var bLevel:Number = levels.indexOf(b.level);
if(aLevel == -1 || bLevel == -1)
throw new Error("Invalid value for criticality ");
if(aLevel == bLevel)
return 0;
if(aLevel > bLevel)
return 1;
return -1;
}
var sort:Sort = new Sort();
sort.compareFunction = sortFunction;
arrayCollection.sort = sort;
arrayCollection.refresh();