30 September 2008

Flex itemRenderers and Recycling Issues

Here's a funky behavior of itemRenderers inside any List-based component (for example, DataGrids). I ran into this and it drove me bunkers until I discovered what was causing it. Here's the scenario.

You have a DataGrid that contains an itemRenderer in one or more columns. Let's say you have a Button control in the renderer that browses for a file on your hard drive and plugs the filename into a TextInput within the same itemRenderer. All is fine -- until you scroll the DataGrid.

You'll notice that other, random TextInput controls in the same column have the same value. What the heck is going on? First inclination is to doubt your event handling code -- it's probably writing to more than one row. After much blood, sweat, and tears, and a lot of research, the answer reveals itself: The itemRenderers are recycled in the List-based controls. In other words, as you scroll, you'll notice the same value present in other itemRenderers without you having updated them. Also, if you scroll up to your updated row, the TextInput field is now blank!

Some articles that will help are here,
There are solutions to this recycling issue (described in the articles). I'm implementing one and will write more as I get it working.

No comments: