开发者

Flex 4 - filtering XMLListCollection in AdvancedDataGrid

开发者 https://www.devze.com 2023-02-28 08:13 出处:网络
I have an advancedDataGrid that is populated with XMLListCollection data.I\'m trying to filter that XMLListCollection but it\'s not refelcting in the ADG.All my tests indicate that it is filtering the

I have an advancedDataGrid that is populated with XMLListCollection data. I'm trying to filter that XMLListCollection but it's not refelcting in the ADG. All my tests indicate that it is filtering the data. Can someone lend a hand??

//
        private function isStory_changeHandler(event:Event):void {
            if (event.currentTarget.selected) {
                myXMLList.filterFunction = filterArray;
                trace("filter");
            } else {
                myXMLList.filterFunction = null;
                trace("don't filter");
            }
            trace(myXMLList.length);
            myXMLList.refresh();
        }
        private function filterArray(item:XML):Boolean {
            var isMatch:Boolean = false;
            if (item.@isStory == "True") {
                isMatch = true;
            }

            return isMatch;
        }
        //

    <mx:AdvancedDataGrid id="mainADG" width="100%" height="100%" dataProvider="{new HierarchicalData(myXMLList)}"
                     draggableColumns="false"
                     itemClick="mainADG_itemClickHandler(event)"
                     doubleClickEnabled="true" itemDoubleClick="mainADG_itemDoubleClickHandler(event)"
                     horizontalGridLines="true" horizontalGridLineColor="#666666"
                     defaultLeafIcon="{null}" folderClosedIcon="{null}" folderOpenIcon="{null}"
                     disclosureClosedIcon="{plus}" disclosureOpenIcon="{minus}"
                     variableRowHeight="true" wordWrap="true"
                     >

    <mx:groupedColumns>
        <mx:AdvancedDataGridColumn headerText="Document title" dataField="@title" fontWeight="bold"/>
        <mx:AdvancedDataGridColumn headerText="Story title" dataField="@isStory" fontWeight="bold"/>
        <mx:AdvancedDataGridColumn headerText="Author" dataField="@author" fontWeight="bold"/>
        <mx:AdvancedDataGridColumn headerText="Publication date" dataField="@pubDate" fontWeight="bold"/>

        <mx:AdvancedDataGridColumnGroup headerText="Tags" sortable="false" >
           开发者_JS百科 <mx:AdvancedDataGridColumn headerText="Name" dataField="@name" sortable="false"/>
            <mx:AdvancedDataGridColumn headerText="Type" dataField="@type" sortable="false"/>
        </mx:AdvancedDataGridColumnGroup>

    </mx:groupedColumns>
</mx:AdvancedDataGrid>


The issue is that you are filtering myXMLList; but the dataProvider is some new variable based off of myXMLList. So, you have two independent instances of the same data, and are filtering the wrong one.

This may be one solution:

    private function isStory_changeHandler(event:Event):void {
        if (event.currentTarget.selected) {
            mainADG.dataProvider.filterFunction = filterArray;
            trace("filter");
        } else {
            mainADG.dataProvider.filterFunction = null;
            trace("don't filter");
        }
        trace(mainADG.dataProvider.length);
        mainADG.dataProvider.refresh();
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号