Wednesday, July 8, 2009

Communication between itemrenderers

ItemRenderers has always been my favourite feature in flex. In one of the tasks I took on, I had to communicate between item renderers to achieve the desired result.

As usual, flex's event architecture was there to aid me achieve this task.

So here is the flow

1.Dispatch an event with bubbles set to true when some user action is performed in the source item renderer or in caase of an inline item renderer call a method using outerDocument like this.
outerDocument.handleFirstColumnChange(data);

2.Have a listener attached to the event dispatched by the source renderer on the parent.Now the parent should re-dispatch the event on the datagrid like
datagrid.dispatcEvent(new Event("itemchangeonfirstcolumn"),data.id));
Note:I am passing the id along with this event so that the target itemrenderers can figure out if they are intended to react or not.

3.Add a listener on the target itemrenderer and on the handler you can do whatever the target is supposed to do.

Here is a simple example The case is that one itemrenderer has to change itself based on a selection done on the other item renderer.

Right clik->viewsource for full source code of the example.

Enjoy!



Bookmark and Share

3 comments:

Pranav said...

Good example

It will help.....

ThanX

Sanjoy said...

Thank You for such an good example.

aXis said...

Thank you for such a good and simple explanation. I needed the source to understand is better, but seems the example is missing.