Flex:如何隐藏AdvancedDataGrid中的行?

Luk*_*mer 1 apache-flex invisible advanceddatagrid show-hide

我有一个AdvancedDataGrid,其ArrayCollection作为dataProvider.例如,我有一个CheckBox,允许我显示或隐藏AdvancedDataGrid中的某些行.

知道我怎么能这样做吗?

Dan*_*Dan 5

我的建议是使用您的数据提供者的filterFunction财产.基本上,您可以为数据提供程序提供一个函数,该函数将确定是否排除ArrayCollection中的给定项(如果项被排除,它将不会显示在AdvancedDataGrid中,实质上使其"不可见").这里的文档filterFunction可以在这里找到.

我建议的是,选中复选框会在数据提供程序中的对象上设置一个属性,然后由过滤器函数使用该属性来包含/排除行.一些(非常粗糙的)伪代码如下:

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"];
}
Run Code Online (Sandbox Code Playgroud)