I need to display DropDownLists in a column of a DataGrid in my Flex application. Here is what I am doing:
First, I have a item renderer function that creates a custom item renderer, and passes it a property that is an IList that will be used as the dataProvider of the dropDownList:
private function rendererFunction(item:Object):ClassFactory {
var itemRenderer:ClassFactory = new ClassFactory(AudActionDropDownIR);
itemRenderer.properties = {AudActionData: AudActionData};
return itemRenderer;
}
This is the code for the custom item renderer class:
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.IList;
[Bindable]
public var TheData:ArrayCollection = new ArrayCollection();
public var AudActionData:IList;
public function init():void
{
TheData = new ArrayCollection(AudActionData.toArray());
TheData.filterFunction = filterTheData;
TheData.refresh();
}
private function filterTheData(item:Object):Boolean {
return item.AUD_STEP_TYPE_ID == data.AUD_STEP_TYPE_ID;
}
]]>
</fx:Script>
<s:DropDownList id="theList"
labelField="AUD_ACTION_DESCR"
requireSelection="true"
selectedIndex="0"
dataProvider="{TheData}"
width="100%"/>
The IList that is passed to the renderer (AudActionData) is converted in to a filtered ArrayCollection that will be used as the dataProvider for the dropdownlist.
I am having a couple of issues with this.
First, how can I call the init function when the renderer is created? Second, when I set the column's itemRendererFunction="rendererFunction", the app will not launch, a white screen comes up. But when I set itemRenderer="components.AudActionDropDownIR", the app will launch, but of course there is no data in the dropdown list.
Any ideas? Thanks!