我有一个包含3列的arrayCollection,例如:
第1列第2列第3列a 1 Xb 2 Yc 3 Zd 4 W
我想转换这组数据,并将其显示在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();
}
我也遇到了同样的问题,并使用水平布局的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>