Update: Solution to disappearing data in your itemRenderer

Posted in ActionScript, Bugs, Flex, How-To on December 8th, 2008 by Kalen Gibbons

In 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″>

<mx:List

dataProvider=”{myData.item}
variableRowHeight=”true
alternatingItemColors=”['#FFFFFF','#E6EEF3']
width=”100%
height=”100%>

 

<mx:itemRenderer>

<mx:Component>

<mx:VBox verticalGap=”0” dataChange=”validateNow()”>

<mx:HBox>

<mx:Label text=”{data.Label}” fontWeight=”bold/>

<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: , , ,

Disappearing data in your itemRenderer?

Posted in ActionScript, Bugs, Flex on October 14th, 2008 by Kalen Gibbons

Note: An update to this post has been posted here. It provides a better solution than the one offered below, so I recommend you check it out.

Although I love Flex, it can still be a bit buggy at times. I was working with an itemRenderer the other day and came across some very odd behavior. I had a list using an itemRenderer and when the data originally loaded everything was fine, but whenever I scrolled some of the data started disappearing. You can see this demonstrated in the sample below.


<mx:List dataProvider="{myData.item}"

variableRowHeight="true"
alternatingItemColors="['#FFFFFF','#E6EEF3']"
width="100%"
height="100%">

 

<mx:itemRenderer>

<mx:Component>

<mx:VBox verticalGap="0">

<mx:HBox>

<mx:Label text="{data.Label}" fontWeight="bold" />
<mx:Label text="{data.date}" color="#999999" />

</mx:HBox>
<mx:Text text="{data.description}" width="100%" />

</mx:VBox>

</mx:Component>

</mx:itemRenderer>

</mx:List>

Apparently, Flex likes to have all the items in a list the same height; so when an item such as the Text field in the example causes variation, Flex simply doesn’t display it. I found that the easiest way to remedy the issue was to set explicit heights for the items in the renderer. Here is an example of how it works with the height explicitly set:


<mx:List dataProvider="{myData.item}"

variableRowHeight="true"
alternatingItemColors="['#FFFFFF','#E6EEF3']"
width="100%"
height="100%">

 

<mx:itemRenderer>

<mx:Component>

<mx:VBox verticalGap="0">

<mx:HBox>

<mx:Label text="{data.Label}" fontWeight="bold" />
<mx:Label text="{data.date}" color="#999999" />

</mx:HBox>
<mx:Text text="{data.description}" width="100%" height="30" />

</mx:VBox>

</mx:Component>

</mx:itemRenderer>

</mx:List>

Now, this isn’t a perfect solution. What we are doing here is effectively the same thing as setting variableRowHeight to false; thus making all the items in the List the same height. So if anybody has a better solution for this issue please let me know.


Tags: , ,

Yet another reason for disappearing background images in IE6

Posted in Bugs, JavaScript on June 10th, 2008 by Kalen Gibbons

I was bit by another IE bug the other day; no matter how much I work with IE I never seem to be immune. That may be due to the fact that IE has sooo many problems. On this occasion several background images were disappearing in IE6. I tried the common solutions first: relative positioning, removing floats, setting widths, etc. and nothing worked. It took me quite a while to uncover the culprit.

href="javascript: void(0);"

 

//I was using it in a common manner:
<a onclick="switchTabs(‘comments’)" href="javascript: void(0);">Comments</a>

Once I removed the href=”javascript: void(0);” from the link everything worked fine. I had searched the Internet for days trying to find the solution to this bug and never found a thing. This is probably because not too many people use href=”javascript: void(0);”… and now I know why.


Tags: ,