How would be the best way of achieving this?
I'll simpify the problem, so this is fairly ficticious...
Let's say I have a class, Student:
public class Student
public var name:String;
public var isActive:Boolean;
public var averageGrade:int; // 0 = A, 1 = B, 2 = C, 3 = D (or whatever)
public var likesCabbage:Boolean;
I have an ArrayCollection of all the students in my school, called allStudents.
I now want to display, on one screen, several views of this ArrayCollection:
1. All Students (ie unfiltered)
2. Students where isActive = true;
3. Students with an average grade of B or above
4. Students that like cabbage.
Obviously, if I simply apply a filter to the ArrayCollection, it will impact on all of these views. So I basically need a filter that is limited to each component.
I could copy the ArrayCollection four times (looping through the original and using addItem() to add each item to the new collections, so they aren't linked) and apply a filter to each new collection, but this seems messy - and among other problems, the new ArrayCollections won't be bound to the original, so if that changes, the others won't be automatically updated.
Is there a best practice for this situation?
ListCollectionView is your friend!
var unfiltered : ListCollectionView = new ListCollectionView( mySourceAC.list );
var active : ListCollectionView = new ListCollectionView( mySourceAC.list );
active.filterfunction = activeFilterFunction;
var graded : ListCollectionView = new ListCollectionView( mySourceAC.list );
graded.filterFunction = gradedFilterfunction;
The Views all wrap the same source so you only need to update that.
You may need to monkey about with refresh() occasionally, but that's a small price to pay!
That looks very much like the answer to my prayers!!!