Skip to main content

Flex datagrid custom itemrenderer recycle issue

When using custom item renderer for a datagrid column, I came upon a problem that caused the grid to show incorrect options.
I was using a HBox to show different action buttons, the action buttons were created dynamically depending on some value of row. What was happening is that the item renderers were being reused and wrong link buttons were added in the HBox.
Here is some literature on the issue.

If you are using a container in an itemrenderer then you need to remove all of its children when the itemrenderer is being created forcing it not to reused.
Here is the code:

<mx:DataGrid >
<mx:DataGridColumn headerText="Actions" >
<mx:HBox >
override public function set data(value:Object):void
protected function hgroup1_creationCompleteHandler():void
//Add children according to values in the row
//var viewDetailsButton:LinkButton = new LinkButton();
//viewDetailsButton.label = "Details";