Question

I have an AdvancedDataGrid with a ArrayCollection as its dataProvider. For instance i have a CheckBox that allows me to show or hide certain rows in the AdvancedDataGrid.

Any idea how i could do that?

Was it helpful?

Solution

My suggestion would be to use your data provider's filterFunction property. Basically, you can give your data provider a function that will determine whether a given item in the ArrayCollection is excluded or not (if an item is excluded, it won't be displayed in the AdvancedDataGrid, in essence making it "invisible"). The docs for filterFunction can be found here.

What I'd suggest then is that checking the checkbox sets a property on the object in your data provider, which is then used by your filter function to include/exclude rows. Some (very rough) pseudocode follows:

private function checkboxClickHandler( event:MouseEvent ):void
{
    /*
       Based on the MouseEvent, determine the row 
       in the data grid you're dealing with
    */

    myDataProvider[someIndex].checkboxFlag = myCheckBox.selected;
    myDataProvider.refresh(); // calling refresh() re-applies the filter to
                              // account for changes.
}

private function myDataProviderFilterFunction( item:Object ):Boolean
{
     // assuming we want the item to be filtered if checkboxFlag is true
     return !item["checkboxFlag"];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top