TrexTroy
TrexTroy

Reputation: 303

Adobe Flex arraycollection

I want to use single collection object to two different UI components. 1. Datagrid and 2nd is chart component. I dont want to change anything inside the arraycollection object but I want to use it at the same time with two different component with minor changes. I know we can use filter function some how but not sure how to apply filter to arraycollection object so that one component (datagrid) can use the original arraycollection object and second component (chart) used the modified one.

Thanks,

Upvotes: 0

Views: 637

Answers (1)

JeffryHouser
JeffryHouser

Reputation: 39408

If you use the same ArrayCollection as the dataProvider for two different components, then any filter or sort applied to that ArrayCollection will show up in both components.

What you want to do cannot be done.

However, you can create multiple ArrayCollections based on the same source and apply filters to them differently. Conceptually something like this:

public var arrayCollection1 : ArrayCollection = new ArrayCollection();
public var arrayCollection2 : ArrayCollection = new ArrayCollection();

protected function onIGotTheArray(value:Array):void{
 arrayCollection1.source = value;
 arrayCollection2.source = value;
 dataGrid.dataProvider = arrayCollection1;
 chart.dataProvider = arrayCollection2;
}

Now you can apply a filter to the first arrayCollection without affecting the second arrayCollection, or vice versa.

This is the preferred approach in my experience.

Upvotes: 4

Related Questions