• 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>

  • 相关阅读:
    java 编程基础 Class对象 反射:代理模式和静态代理
    sql优化(排序)
    Mysql备份恢复
    Mysql5.7.33安装
    Networker oracle备份恢复
    Centos7 安装11.2.0.4
    spring security 自定义多种方式登录授权
    CentOS 7 安装Nginx 并配置自动启动
    Nginx 配置模板
    Alibaba cloud 版本说明
  • 原文地址:https://www.cnblogs.com/taobataoma/p/1034065.html
Copyright © 2020-2023  润新知