2012-11-07 35 views
0

顯示hierarchial數據顯示覆選框,在我的DataGrid的先進,我顯示hierachial數據。而不是文件夾圖標,我需要顯示一個複選框,我可以選擇或取消選擇它。根據所選的複選框,我需要顯示選定的單元格值。 Plz讓我知道如何實現它。如何在柔性先進數據網格

回答

0

下面的代碼可以幫助你: - 如果你願意,你可以實現它的邏輯。

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 
      import mx.events.ListEvent; 

      [Bindable] 
      private var dpHierarchy:ArrayCollection = new ArrayCollection([ 
       {Region:"Southwest", categories: [ 
        {Region:"Arizona", categories: [ 
         {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000}, 
         {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
        {Region:"Central California", categories: [ 
         {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
        {Region:"Nevada", categories: [ 
         {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
        {Region:"Northern California", categories: [ 
         {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000}, 
         {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
        {Region:"Southern California", categories: [ 
         {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000}, 
         {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}]} 
       ]} 
      ]); 


      protected function onItemClick(event:ListEvent):void 
      { 
       myADG_ID.expandItem(myADG_ID.selectedItem,!myADG_ID.isItemOpen(myADG_ID.selectedItem)); 
      } 



     ]]> 
    </fx:Script> 

    <mx:AdvancedDataGrid id="myADG_ID" width="100%" height="100%" defaultLeafIcon="{null}" 
         folderOpenIcon="{OpenCheckBox}" folderClosedIcon="{CloseCheckBox}" 
         itemClick="onItemClick(event)" 
         displayDisclosureIcon="false"> 
     <mx:dataProvider> 
      <mx:HierarchicalData source="{dpHierarchy}" 
           childrenField="categories"/> 
     </mx:dataProvider> 
     <mx:columns> 
      <mx:AdvancedDataGridColumn dataField="Region"/> 
      <mx:AdvancedDataGridColumn dataField="Territory_Rep" 
             headerText="Territory Rep"/> 
      <mx:AdvancedDataGridColumn dataField="Actual"/> 
      <mx:AdvancedDataGridColumn dataField="Estimate"/> 
     </mx:columns> 
    </mx:AdvancedDataGrid> 
</s:Application> 

OpenCheckBox.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" 
            focusEnabled="true" width="100%" height="100%"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <s:CheckBox id="cbSelector" selected="true" width="100%" /> 
</s:MXAdvancedDataGridItemRenderer> 

CloseCheckBox.mxml

<?xml version="1.0" encoding="utf-8"?> 
<s:MXAdvancedDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:mx="library://ns.adobe.com/flex/mx" 
            focusEnabled="true" width="100%" height="100%"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
    </fx:Declarations> 
    <s:CheckBox id="cbSelector" selected="false" width="100%" /> 
</s:MXAdvancedDataGridItemRenderer> 
+0

感謝您的代碼。但根據你的代碼,對於childnodes複選框沒有得到顯示。假設亞利桑那州下有這些節點的子區域複選框不存在 – Srivi

+0

你的意思是說你的Hierarchy的最後一個孩子的CheckBox?沒有使用CheckBox,如果這是最後一個孩子,因爲用戶無法展開它... CheckBox對於每個層次結構數據而言都不可見。 –

+0

我不希望複選框顯示在頂部節點上 – Srivi