我有一个使用XMLListCollection数据填充的advancedDataGrid。我正在尝试过滤那个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>
答案 0 :(得分:1)
问题是你正在过滤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();
}