zoukankan      html  css  js  c++  java
  • 动态显示/隐藏 DataGrid 的列

    在List中选中一个就会显示相应的 DataGrid 的列
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" horizontalAlign="left"
        creationComplete
    ="initApp()">
    <mx:Script><![CDATA[
      import mx.controls.dataGridClasses.DataGridColumn;
      //import mx.controls.DataGrid;
      import mx.collections.XMLListCollection;
      
      [Bindable]
    private var _xlcCatalog:XMLListCollection;    //the dataProvider for the DG

    //run by creationComplete
    public function initApp():void
    {
        _xlcCatalog = new XMLListCollection(xmlCatalog.product);      //wrap the XML product nodes in an XMLListCollection
        lstColumns.selectedItems = new Array(dgHideShow.columns[0]);  //set the column list dataProvider to the DataGridColumns
    }//initApp

    private function hideShowColumns():void  {
       var aColumns:Array = dgHideShow.columns;
       var aSelectedColumns:Array = lstColumns.selectedItems;
       var dgc:DataGridColumn;
       var sDataField:String;
       var sDataFieldCur:String;
       var bFound:Boolean
       for (var i:int=0;i<aColumns.length;i++)  {
         bFound = false
         dgc = aColumns[i];
         sDataField = dgc.dataField;
         for (var j:int=0;j<aSelectedColumns.length;j++)  {
           sDataFieldCur = aSelectedColumns[j].dataField;
           if (sDataFieldCur == sDataField)  {
             bFound = true;
             break;
           }
         }//for (var j:
         if (bFound) {
           dgc.visible = true;
         }  
         else  {
           dgc.visible = false;
         }     
       }// for (var i:
    }//

    ]]></mx:Script>   
      
    <mx:VBox>
        
    <mx:Label text="Multi-Select" />
        
    <mx:Label text="Columns" />
        
    <mx:List id="lstColumns" dataProvider="{dgHideShow.columns}" 
            labelField
    ="dataField" 
            allowMultipleSelection
    ="true"
            click
    ="hideShowColumns()"  />    
      
    </mx:VBox>

      
    <mx:DataGrid id="dgHideShow" dataProvider="{_xlcCatalog}" rowCount="6" >
        
    <mx:columns>
          
    <mx:Array>
            
    <mx:DataGridColumn headerText="Product" dataField="name" visible="true" />
            
    <mx:DataGridColumn headerText="Description" dataField="description" visible="false" />
            
    <mx:DataGridColumn headerText="Price" dataField="price" visible="false" />
            
    <mx:DataGridColumn headerText="Series" dataField="series" visible="false" />
            
    <mx:DataGridColumn headerText="Tri-Band" dataField="triband" visible="false" />
            
    <mx:DataGridColumn headerText="Camera" dataField="camera" visible="false" />
           
    </mx:Array>
        
    </mx:columns>    
      
    </mx:DataGrid>

      
    <mx:XML id="xmlCatalog">
        
    <catalog>
          
    <product productId="1">
            
    <name>Nokia 6010</name>
            
    <description>Easy to use without sacrificing style, the Nokia 6010 phone offers functional voice communication supported by text messaging, multimedia messaging, mobile internet, games and more</description>
            
    <price>99.99</price>
            
    <image>assets/pic/Nokia_6010.gif</image>
            
    <series>6000</series>
            
    <triband>false</triband>
            
    <camera>false</camera>
            
    <video>false</video>
            
    <highlight1>MMS</highlight1>
          
    <highlight2>Large color display</highlight2>
          
    </product>
          
    <product productId="2">
            
    <name>Nokia 3100 Blue</name>
            
    <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on™ gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
            
    <price>139</price>
            
    <image>assets/pic/Nokia_3100_blue.gif</image>
            
    <series>3000</series>
            
    <triband>true</triband>
            
    <camera>false</camera>
            
    <video>false</video>
            
    <highlight1>Glow-in-the-dark</highlight1>
          
    <highlight2>Flashing lights</highlight2>
          
    </product>
          
    <product productId="3">
            
    <name>Nokia 3100 Pink</name>
            
    <description>Light up the night with a glow-in-the-dark cover - when it's charged with light you can easily find your phone in the dark. When you get a call, the Nokia 3100 phone flashes in tune with your ringing tone. And when you snap on a Nokia Xpress-on™ gaming cover*, you'll get luminescent light effects in time to the gaming action.</description>
            
    <price>139</price>
            
    <image>assets/pic/Nokia_3100_pink.gif</image>
            
    <series>3000</series>
            
    <triband>true</triband>
            
    <camera>false</camera>
            
    <video>false</video>
            
    <highlight1>Glow-in-the-dark</highlight1>
          
    <highlight2>Flashing lights</highlight2>
          
    </product>
          
    <product productId="4">
            
    <name>Nokia 3120</name>
            
    <description>Designed for both business and pleasure, the elegant Nokia 3120 phone offers a pleasing mix of features. Enclosed within its chic, compact body, you will discover the benefits of tri-band compatibility, a color screen, MMS, XHTML browsing, cheerful screensavers, and much more.</description>
            
    <price>159.99</price>
            
    <image>assets/pic/Nokia_3120.gif</image>
            
    <series>3000</series>
            
    <triband>true</triband>
            
    <camera>false</camera>
            
    <video>false</video>
            
    <highlight1>Multimedia messaging</highlight1>
          
    <highlight2>Animated screensavers</highlight2>
          
    </product>
          
    <product productId="5">
            
    <name>Nokia 3220</name>
            
    <description>The Nokia 3220 phone is a fresh new cut on some familiar ideas - animate your MMS messages with cute characters, see the music with lights that flash in time with your ringing tone, download wallpapers and screensavers with matching color schemes for the interface.</description>
            
    <price>159.99</price>
            
    <image>assets/pic/Nokia_3220.gif</image>
            
    <series>3000</series>
            
    <triband>false</triband>
            
    <camera>true</camera>
            
    <video>false</video>
            
    <highlight1>MIDI tones</highlight1>
          
    <highlight2>Cut-out covers</highlight2>
          
    </product>
        
    </catalog>
      
    </mx:XML>
    </mx:Application>


     
  • 相关阅读:
    linux 常用awk命令
    plsql连接oralce数据的配置 PLSQL配置怎么连ORACLE plsql连接多个数据库设置 Oracle 服务命名(别名)的配置及原理,plsql连接用
    PLSQL连接ORACLE配置字符串简介 oracle网络配置 三个配置文件 listener.ora、sqlnet.ora、tnsnames.ora原理解释
    OLEDB和ODBC的区别(优缺点)
    ADO,OLEDB,ODBC,DAO,RDO的区别说明
    Android开发在路上:少去踩坑,多走捷径
    手机淘宝构架演化实践
    车​险​与​非​车​险​基础分​类​和​说​明
    192.168.1.1地址,路由器地址打不开怎么办?
    一般测试流程 常用的软件测试工具有哪些? 开源测试工具 软件测试一般用到的工具、框架、技术列表
  • 原文地址:https://www.cnblogs.com/nianshi/p/1752257.html
Copyright © 2011-2022 走看看