How to add datagrid column name in Adobe Flex
I have defined the datagrid as follows
<mx:DataGrid id="dg" width="100%" height="100%" >
In the part i am trying to get the details from the database and setting the dataProvider for the DataGrid as follows.
var arr开发者_高级运维ayContent:ArrayCollection = new ArrayCollection();
for(var i:int=0;i<assetClassDetails.length;i++)
{
var assetClass_:AssetItemClassVO = new AssetItemClassVO();
var array:ArrayCollection = new ArrayCollection();
var embeddableLocale:EmbeddableAssetItemClassLocale = new EmbeddableAssetItemClassLocale();
var assetClassD_:AssetItemClassLocale = new AssetItemClassLocale();
assetClass_ = assetClassDetails.getItemAt(i) as AssetItemClassVO;
array = assetClass_.assetItemClassLocale;
if(assetClass_ != null && array != null && array.length >0)
{
assetClassD_ = array.getItemAt(0) as AssetItemClassLocale;
arrayContent.addItem(new Array(assetClass_.id,assetClassD_.name,assetClassD_.description,assetClassD_.locale,assetClass_.createdby,assetClass_.createdtime,assetClass_.lastmodifiedby,assetClass_.lastmodifiedtime));
}
}
dg.dataProvider = arrayContent;
But after doing this, I am getting the column name as 1,2,3,4,5 ...8. But I want to set theColumn name as ID,Name,Description,Locale,CreatedBy,CreatedTime,LastModifiedBy,LastModifiedTime.
How do i do it?
Please help.
I am not sure about the data on arraycollection, maybe you can check my code, i create dynamic table on Datagrid
private function addDataGridParamColumn(tmp:String):void
{
var dgColumn:DataGridColumn = new DataGridColumn(tmp);
var arr:Array = dg.columns;
dg.headerRenderer = new ClassFactory(Label);
switch(tmp)
{
case "Name":
dgColumn.dataField = 'Name';
dgColumn.width = 150;
dgColumn.itemRenderer = new ClassFactory(Label);
break;
}
arr.push(dgColumn);
dg.columns = arr;
}
you can call function addDataGridParamColumn(this is the name header) and add case for looping
Not 100% sure what you're trying to do, but here's an example of DataGrid data binding. Hope it helps.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application initialize="init()"
xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var employees:ArrayCollection;
private function init():void
{
employees = new ArrayCollection();
employees.addItem({name: "Oscar", phone: "907.123.4567", email: "oscar@isacat.net"});
employees.addItem({name: "Nimrod", phone: "907.876.5342", email: "nimrod@isacat.net"});
}
]]>
</mx:Script>
<mx:DataGrid id="dg" color="0x323232" width="100%" rowCount="3" dataProvider="{employees}">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name"/>
<mx:DataGridColumn dataField="phone" headerText="Phone"/>
<mx:DataGridColumn dataField="email" headerText="Email"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
精彩评论