Tuesday, November 15, 2011

Passing data between datagrid itemRenderers


Recently I had to build a component where I had to communicate between item renderers of 2 columns in a datagrid to keep them updated. What made the task more worthwhile was that the item renderers were combo boxes, the data providers for which came from an external source and not the data provider for the datagrid. So, here's how I went on about it. 


1. The datagrid dataprovider was set and the dataField for each of the column item renderers were added.
2. In the first item renderer, set the dataprovider for the combobox and add an event listener for the change event. In the event listener formulate a new event that  sends the itemIndex of the renderer and the selected data.
3. On the creation complete of the second itemrenderer add the event listener for the above event on the parentDocument.
4. In the handler function, if the itemIndex matches then based on the selected data, change the display.


And lo and behold!! We are all set.

No comments :