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 ,如需转载请自行联系原作者

相关文章
|
7月前
(145) Table ‘./addon_collect_wukong_spider‘ is marked as crashed and should be repaired解决思路
(145) Table ‘./addon_collect_wukong_spider‘ is marked as crashed and should be repaired解决思路
30 0
|
算法 搜索推荐 数据库
一个有点咬文嚼字的 sorting 和 ordering
为什么排序算法的英文是 sorting 而不是 ordering。
146 0
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
Data Structures and Algorithms (English) - 6-6 Level-order Traversal(25 分)
108 0
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
PAT (Advanced Level) Practice - 1143 Lowest Common Ancestor(30 分)
129 0
PAT (Advanced Level) Practice - 1098 Insertion or Heap Sort(25 分)
PAT (Advanced Level) Practice - 1098 Insertion or Heap Sort(25 分)
108 0
|
SQL 移动开发 算法
New Dynamic Programming Algorithm for the Generation of Optimal Bushy Join Trees
MySQL无疑是现在开源关系型数据库系统的霸主,在DBEngine的最新排名中仍然稳居第2位,与第3位SQL Server的积分差距并不算小,可以说是最受欢迎,使用度最高的数据库系统,这一点看看有多少新型数据库要兼容MySQL的协议和语法就知道了。
346 0
New Dynamic Programming Algorithm for the Generation of Optimal Bushy Join Trees
|
SQL 关系型数据库 MySQL
Accelerating Queries with Group-By and Join By Groupjoin
这篇paper介绍了HyPer中引入的groupjoin算子,针对 join + group by这种query,可以在某些前提条件下,在join的过程中同时完成grouping+agg的计算。 比如用hash table来实现hash join和group by,就可以避免再创建一个hash table,尤其当join的数据量很大,产生的group结果又较少时,可以很好的提升执行效率。
359 0
Accelerating Queries with Group-By and Join By Groupjoin
成功解决FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `ar
成功解决FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `ar
|
算法 搜索推荐 索引
Data Structure_Sort Algorithm
排序算法 Tool implement //generate a array of n elements, range [rangL, rangeR] int *generateRandomArray(int n, int rangL, ...
931 0