Update: Solution to disappearing data in your itemRenderer
Posted in ActionScript, Bugs, Flex, How-To on December 8th, 2008 by Kalen GibbonsIn a previous post I explained how a rendering bug in Flex was causing items to disappear in an itemRenderer. In the example below, you can see that when you scroll, the items in the list disappear. This is caused by the varying heights of the elements. If you explicitly set the height for each element or set variableRowHeights to false, then the problem goes away.
What was causing the problem was apparent but the solution was not. Thankfully, Olivier Lalonde was nice enough to shed some light on an easy fix. The itemRenderer needs to be validated as the user scrolls. So, as Olivier suggests, you simply need to listen for the dataChange event and execute the validateNow() function.
You can see in the example below that the list now has varying row heights… and the data no longer disappears. NICE! The key point to focus on here is the following line: <mx:VBox dataChange=”validateNow()” verticalGap=”0″>
variableRowHeight=”true“
alternatingItemColors=”['#FFFFFF','#E6EEF3']“
width=”100%“
height=”100%“>
<mx:itemRenderer>
<mx:Label text=”{data.date}” color=”#999999” />
</mx:HBox>
<mx:Text text=”{data.description}” width=”100%” />
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
Tags: dataChange, itemRenderer, List, validateNow