Drive Multiple Views with a Single Data Source

Have you ever found yourself taking a stream of data and chunking it out into multiple arrays or collections to drive multiple controls? You really don't have to... and I'll show you how.

The approach involves pointing a components dataProvider at a parameterized bindable method.

  1. [Bindable(event="itemsChanged")]
  2. private function filteredProvider( value : string = "" ):Array
  3. {
  4.   ...

Which allows you to do something like this:

  1. <mx:DataGrid y="100" width="400" dataProvider="{filteredProvider()}"/>

...or...

  1. <mx:DataGrid y="300" width="400" dataProvider="{filteredProvider('db')}"/>

...or...

  1. <mx:DataGrid y="500" width="400" dataProvider="{filteredProvider('web server')}"/>

The down-side of this approach is that each time a refresh event is dispatched all the controls tied to the filtered provider will update... for titanic size arrays or collections you might need to make adjustments for optimal performance.

Take a look at the example and source to see how its all hooked up. Binding is your friend... and it smells nice too!

[ example: Filtered Data Provider ]
[ source: Filtered Data Provider ]