2012-09-04 93 views
1

我有3列作爲這樣一個ArrayCollection:如何轉置數據在Flex中的數據網格

Col1中col2的COL3 1 X B 2ý ç3 Z d 4瓦特

欲轉移這組數據並將其顯示在Flex DataGrid中。

我已經得到這裏與我的功能下面,網格顯示(a,b,c,d等)爲列但行沒有填充。例如,第一列應顯示「a」作爲標題,第一行顯示「1」,第二行顯示「X」。

有人可以幫助我這個。

這是我的功能。

public function createColumns(myArrayColl:ArrayCollection):void{ 
    var advancedDataGridColumn:AdvancedDataGridColumn; 
    var i:int; 
    var columnsArray:Array = new Array(); 
    for(i=0;i< myArrayColl.length;i++){           
     advancedDataGridColumn=new AdvancedDataGridColumn();    
     advancedDataGridColumn.headerText= getFormattedPeriod(myArrayColl[i].Col1.toString()); 
     advancedDataGridColumn.dataField=myArrayColl[i].Col2.toString(); 
       advancedDataGridColumn.dataField=myArrayColl[i].Col2.toString(); 
       advancedDataGridColumn.dataField=myArrayColl[i].Col3.toString(); 


     columnsArray.push(advancedDataGridColumn); 
    } 
    adg1.columns = columnsArray; 
    adg1.invalidateDisplayList(); 
} 
+0

誰能幫助請.. – FlexyBoz

回答

0

我有同樣的問題,並使用Spark DataGroup與水平佈局解決:

<?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"> 
    <fx:Script> 
     <![CDATA[ 
      import mx.collections.ArrayCollection; 
      [Bindable] private var array : ArrayCollection = new ArrayCollection([ 
       {Col1:"a",Col2:"1",Col3:"X"}, 
       {Col1:"b",Col2:"2",Col3:"Y"}, 
       {Col1:"c",Col2:"3",Col3:"Z"}, 
       {Col1:"d",Col2:"4",Col3:"W"}, 
      ]); 
     ]]> 
    </fx:Script> 
    <s:HGroup x="225" y="49"> 
     <!--the VGroup below it's a kind of a 'vertical header'. If you, like use it.--> 
     <s:VGroup width="50" id="vHeader"> 
      <s:Label text="Col 1" fontWeight="bold"/> 
      <s:Label text="Col 2"/> 
      <s:Label text="Col 3"/> 
     </s:VGroup> 
     <!--the DataGroup with Horizontal layout and a itemRenderer using a VGroup--> 
     <s:DataGroup id="dataGroup" clipAndEnableScrolling="true" 
        dataProvider="{array}" width="100"> 
      <s:layout> 
       <s:HorizontalLayout gap="1" useVirtualLayout="true"/> 
      </s:layout> 
      <s:itemRenderer> 
       <fx:Component> 
        <s:ItemRenderer width="49"> 
         <fx:Script> 
          <![CDATA[ 
          ]]> 
         </fx:Script> 
         <s:VGroup> 
          <s:Label text="{data.Col1}" fontWeight="bold"/> 
          <s:Label text="{data.Col2}"/> 
          <s:Label text="{data.Col3}"/> 
         </s:VGroup> 
        </s:ItemRenderer> 
       </fx:Component> 
      </s:itemRenderer> 
     </s:DataGroup> 
    </s:HGroup> 
    <!--the HSCrollBar positioned above the dataGroup--> 
    <s:HScrollBar x="276" y="27" width="100" pageSize="50" stepSize="50" 
        viewport="{dataGroup}"/> 
</s:Application> 
相關問題