flex4.0 datagrid怎么动态添加itemrenderer 20
AdvancedDataGrid根据ID去动态添加列。列动态绑定itemrenderer,里面实现类似输入框,。之前静态...
AdvancedDataGrid 根据ID去动态添加列。列动态绑定itemrenderer ,里面实现类似输入框,。
之前静态 展开
之前静态 展开
1个回答
2013-11-29
展开全部
给你个例子
<?xml version="1.0"?>
<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;
import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
private var fields:Array = ['id', 'name'];
private var ac:ArrayCollection = new ArrayCollection([
{id: 1, name: 'aaaa'},
{id: 2, name: 'bbbb'},
{id: 3, name: 'cccc'}
]);
private function button1_clickHandler(e:MouseEvent):void {
var columns:Array = [];
for each (var field:String in fields) {
var column:AdvancedDataGridColumn = new AdvancedDataGridColumn();
column.dataField = column.headerText = field;
if(field == 'name') {
column.itemRenderer = new ClassFactory(TextInputRenderer);
}
columns.push(column);
}
adg.dataProvider = ac;
adg.columns = columns;
}
]]></fx:Script>
<fx:Declarations>
<fx:Component id="myComponent" className="TextInputRenderer">
<mx:TextInput text="@{data.name}"/>
</fx:Component>
</fx:Declarations>
<mx:AdvancedDataGrid id="adg" width="400" height="300">
</mx:AdvancedDataGrid>
<s:controlBarContent>
<s:Button label="create columns" click="button1_clickHandler(event)"/>
</s:controlBarContent>
</s:Application>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询