I got an email this afternoon asking if you could use the same technique in my last post - but use XML as the data source. Of course you can! Here is an example with source that shows you how.
The changes are trivial... we can easily change the return type from an Array to an XMLList.
[Bindable(event="itemsChanged")]
private function filteredProvider
( value : string =
"" ) : XMLList
{
...
To keep things simple, we can just use E4X to process the result.
if ( value == "" )
return _items.elements("item");
return _items.item.(@type == value);
}
The MXML implementation doesn't change:
<mx:DataGrid y="100" width="400" dataProvider="{filteredProvider()}"/>
...or...
<mx:DataGrid y="300" width="400" dataProvider="{filteredProvider('db')}"/>
...or...
<mx:DataGrid y="500" width="400" dataProvider="{filteredProvider('web server')}"/>
As I mentioned before, the down-side of this approach is that you can't isolate updates between controls that are tied to a single data source. As long as you are wise in your implementation - you should be good-to-go.
I've modified the example and source so that you can see what changes need to be made to use XML in lieu of an Array. Binding loves you... and little dog Totto too!
[ example: Filtered XML Data Provider ]
[ source: Filtered XML Data Provider ]