PDA

View Full Version : Passing data to Custom ItemEditor


bzouchir
04-15-2008, 12:58 PM
Hi everyone,

I was wondering if there is a way to pass data to a custom itemEditor in a DataGrid.

for instance let's say I have a SomeComponent.mxml that I am using as itemEditor in MainApp.mxml

<mx:Application ...>
<mx:Script>
<![CDATA[
private var foo:Array;
]]>
</mx:Script>
<mx:DataGrid ... >
<mx:DataGridColumn headerText="File" editable="true" editorDataField="newImage" itemEditor="SomeComponent">
</mx:DataGrid>
</mx:Application>

my question is:
how can i pass the "foo" attribute to the "SomeComponent" itemEditor?

all the examples i have seen are using hardcoded static data.
"SomeComponent" is a ComboBox fed with dynamic data "foo"

I can call the server back from the "SomeComponent" but isn't there an easier more efficient way!?

I will appreciate any help.

thanks

mattb
04-16-2008, 12:29 AM
Do you need to send the entire foo array into your itemEditor, or just the array element relevant to the particular row you want to edit?

If the latter, your SomeComponent instance should have a property called "data" that contains the array element for that row. If the former, there are several options but one way would be to fire a custom event when the control is created, handle the event in your app and apply the foo array to the instance that is passed via event.target in the event handler.

bzouchir
04-16-2008, 01:35 AM
I actually would like to pass the entire foo array into the itemEditor.

Firing that event sounds like a great idea, didn't cross my mind!!

thanks a lot mate will give it a go and post the result, sure it will work!

cheers