Categories
Flex

DataGrid with Multiple Pulldowns

Here is an example that illustrates how you need to add some additional logic when you add ItemRenderers into a DataGrid. The way I came across this problem is I noticed that when I had ItemRenderers doing things like checkboxes or pulldowns, the choices that they were set to on a row basis would CHANGE whenever I scrolled or sorted a column.

I struggled with finding a way, as I talk about in another posting, and found that using the dataChange event does the trick, and I always create the ItemRenderer as a separate component instead of trying to put all the logic in the main mxml. The component gets the initial setting of the value for that cell via “.data” and then you need to maintain and check it within the component. This can end up with the coder doing some hacking, and my example is only that — an example. I’m sure there are more elegant ways to achieve this. But that’s one of the things I think Flex shares with Perl — there are always multiple ways to get something done!

Take a look at the first flash example, where I DON’T use the dataChange — then see how it works nicely on the 2nd example.

First example (Try sorting columns and see it randomizes each time):

This movie requires Adobe Flash Player — Download at www.adobe.com

Second example (Works!):

This movie requires Adobe Flash Player — Download at www.adobe.com

Download my code sample here.

Leave a Reply

Your email address will not be published. Required fields are marked *