Flex 4 - 在 AdvancedDataGrid 中过滤 XMLListCollection

发布于 2024-11-03 02:22:30 字数 2322 浏览 2 评论 0原文

我有一个用 XMLListCollection 数据填充的 advanceDataGrid。我正在尝试过滤该 XMLListCollection,但它没有反映在 ADG 中。我所有的测试都表明它正在过滤数据。有人可以帮忙吗?

//
        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" >
            <mx:AdvancedDataGridColumn headerText="Name" dataField="@name" sortable="false"/>
            <mx:AdvancedDataGridColumn headerText="Type" dataField="@type" sortable="false"/>
        </mx:AdvancedDataGridColumnGroup>

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

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" >
            <mx:AdvancedDataGridColumn headerText="Name" dataField="@name" sortable="false"/>
            <mx:AdvancedDataGridColumn headerText="Type" dataField="@type" sortable="false"/>
        </mx:AdvancedDataGridColumnGroup>

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扭转时空 2024-11-10 02:22:30

问题是您正在过滤 myXMLList;但 dataProvider 是一些基于 myXMLList 的新变量。因此,您有相同数据的两个独立实例,并且过滤了错误的实例。

这可能是一种解决方案:

    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();
    }

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();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文