Pretty simple one this and therefore I wasn’t going to bother posting it, but I’ve passed it on a few people as a solution to a problem they had so maybe others will find it useful.
Using the FilteredDataGrid you bind to your original source, but then pass a method reference through to the FilteredDataGrid’s filterFunction property and filter out any data in the dataProvider that you don’t want or isn’t valid.
[as]package ws.tink.flex.controls
{
import mx.controls.DataGrid;
public class FilteredDataGrid extends DataGrid
{
private var _originalDataProvider : Object;
private var _filterFunction : Function;
override public function set dataProvider( value:Object ):void
{
super.dataProvider = filterDataProvider( value );
}
public function set filterFunction( value:Function ):void
{
_filterFunction = value;
if( _originalDataProvider ) dataProvider = _originalDataProvider;
}
public function filterDataProvider( value:Object ):Object
{
_originalDataProvider = value;
return ( _filterFunction != null ) ? _filterFunction( value ) : value;
}
}
}[/as]
and here’s an example of it in action with the source…
FilteredDataGridExample
NOTE: I’ve edited the code slightly so you can toggle on and off the filter fucnction. The example above shows this in action.
The same results could be achieved without the FilteredDataGrid, but it saves you having to…
1. Set up your own var to bind with the dataprovider.
2. Setting up the binding yourself to invoke the filter function.
You would then in the filter function assign the new values to your var that is bound to the dataProvider.