Sorting and filtering data in an XMLListCollection

简介:
The following code is a brief example of sorting a Flex XMLListCollection using the Sort and SortField classes, and the  XMLListCollection.sort  property. We also look at filtering the XMLCollection using a custom filter function.
<? xml version="1.0" encoding="utf-8" ?>
<!--  http://blog.flexexamples.com/2007/08/22/sorting-and-filtering-data-in-an-xmllistcollection/  -->
< mx:Application  xmlns:mx ="http://www.adobe.com/2006/mxml"
        layout
="vertical"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init()" >

    
< mx:Script >
        
<![CDATA[
            import mx.collections.SortField;
            import mx.collections.Sort;
            import mx.controls.*;

            private function init():void {
                describeTypeXML = describeType(DataGrid);
                factoryMethodsXLC.source = describeTypeXML.factory.method;
            }

            private function sortXLC():void {
                var nameSort:Sort = new Sort();
                nameSort.fields = [new SortField('@name', true)];

                factoryMethodsXLC.sort = nameSort;
                factoryMethodsXLC.refresh();
            }

            private function filterXLC():void {
                if (filterCh.selected) {
                    factoryMethodsXLC.filterFunction = declaredBy_filterFunc;
                    factoryMethodsXLC.refresh();
                } else {
                    factoryMethodsXLC.filterFunction = null;
                    factoryMethodsXLC.refresh();
                }
            }

            private function declaredBy_filterFunc(item:XML):Boolean {
                return item.@declaredBy == describeTypeXML.@name;
            }
        
]]>
    
</ mx:Script >

    
< mx:XML  id ="describeTypeXML"   />

    
< mx:XMLListCollection  id ="factoryMethodsXLC"   />

    
< mx:VBox >
        
< mx:DataGrid  id ="factoryMethodsGrid"
                dataProvider
="{factoryMethodsXLC}"
                width
="400"
                rowCount
="7" >
            
< mx:columns >
                
< mx:DataGridColumn  dataField ="@name"   />
                
< mx:DataGridColumn  dataField ="@returnType"   />
                
< mx:DataGridColumn  dataField ="@declaredBy"   />
            
</ mx:columns >
        
</ mx:DataGrid >
        
< mx:HBox  width ="100%" >
            
< mx:Button  id ="sortBtn"
                    label
="Sort ({factoryMethodsGrid.dataProvider.length} items)"
                    click
="sortXLC()"   />
            
< mx:Spacer  width ="100%"   />
            
< mx:CheckBox  id ="filterCh"
                    label
="{describeTypeXML.@name} only"
                    click
="filterXLC()"   />
        
</ mx:HBox >
    
</ mx:VBox >

</ mx:Application >




    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/10/1034065.html ,如需转载请自行联系原作者

相关文章
|
10月前
|
算法 Linux Shell
SGAT丨Single Gene Analysis Tool
SGAT丨Single Gene Analysis Tool
|
自然语言处理
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
69 0
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
Neither Quantity object nor its magnitude supports indexing
Neither Quantity object nor its magnitude supports indexing
|
算法 搜索推荐 数据库
一个有点咬文嚼字的 sorting 和 ordering
为什么排序算法的英文是 sorting 而不是 ordering。
108 0
|
数据可视化 数据挖掘 开发者
Data-Basic Statistical Descriptions of Data| 学习笔记
快速学习 Data-Basic Statistical Descriptions of Data。
112 0
Data-Basic Statistical Descriptions of Data| 学习笔记
|
机器学习/深度学习 自然语言处理 搜索推荐
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
Re25:读论文 Lecut+JOTR Incorporating Retrieval Information into the Truncation of Ranking Lists in the
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
88 0
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
196 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
89 0
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
PAT (Advanced Level) Practice - 1096 Consecutive Factors(20 分)
119 0