我有一個mx:Datagrid女巫我想添加一個組合框作爲項目渲染器。Flex mx:DataGrid - 創建組合框ItemRenderer
<mx:DataGrid id="dgEnsActes"
horizontalScrollPolicy="on"
dataProvider="{arListeDevis}"
width="100%" height="100%" >
<mx:columns>
<mx:DataGridColumn dataField="dvIndex" headerText="" headerStyleName="dgHeader" fontWeight="normal" width="40"/>
<mx:DataGridColumn dataField="dvLibelle" headerText="Libellé" headerStyleName="dgHeader" wordWrap="true" fontWeight="normal" width="180"/>
<mx:DataGridColumn dataField="dvTotal" headerText="Total" headerStyleName="dgHeader" width="60" fontWeight="normal"/>
<mx:DataGridColumn dataField="dvStatut" headerText="Statut"
rendererIsEditor="true" editorDataField="result" itemRenderer="fr.inters.ui.itemRenderer.irComboEtatDevis"
wordWrap="true" headerStyleName="dgHeader" fontWeight="normal" width="70"/>
<mx:DataGridColumn dataField="dvAcceptDirect" headerText="Création" headerStyleName="dgHeader" width="60" fontWeight="normal"/>
</mx:columns>
</mx:DataGrid>
我的自定義項目渲染是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer 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">
<fx:Script>
<![CDATA[
public var result:String="";
[Bindable] var dpValue:Array=[
{label:"Accepté", data:"Accepté"},
{label:"Refusé", data: "Refusé"},
{label:"En attente", data: "En attente"}];
override public function set data(value:Object):void
{
super.data = value;
if (value != null)
{
var currentValue:String = value.size;
var len:int = dpValue.length;
for (var i:int = 0; i < len; i++)
{
if (dpValue[i].data == currentValue)
{
editor.selectedIndex = i;
break;
}
}
}
}
public function onChange():void
{
var index:int = editor.selectedIndex;
result = dpValue[index].data;
}
]]>
</fx:Script>
<mx:ComboBox id="editor" dataProvider="{dpValue}" width="130" change="onChange()"/>
</s:MXDataGridItemRenderer>
但是,當我嘗試調試一個錯誤出現,該消息是selectedIndex is undefined
是有人幫我嗎?
謝謝
謝謝這個項目編輯器運作良好,但你知道如何做與itemrenderer相同。事實上,在我的情況下,如果我將itemEditor修改爲itemrenderer,會出現一個錯誤/ – Flex60460
您是否可以更改editible =「false」並僅將其用於顯示?請參閱http://www.adobe.com/devnet/flex/videotraining/exercises/ex4_05.html獲取更多建議。稍後我會回到你身邊,當我回到家時,看看我使用itemrenderers寫的代碼。 – ShaunOReilly
如果y把可編輯爲true,那就沒問題。但在數據網格上,我們顯示標籤而不是組合框。謝謝 – Flex60460