views:

564

answers:

1

I have an item renderer that checks an external source for display information. If that information changes, I want to force all item renderer instances to check it.

What's the best way for force all the item renderers in a list or grid to either commitProperties or execute some other method?

  • I've read that resetting the grid.itemRenderer property will make them all initialize.

  • I've also received the suggestion to iterate recursively through all the grid's children and call invalidateProperties on all the UIComponents I find.

Any thoughts? Alternatives?

A: 

Remember that in Flex Lists you're dealing with virtualization and itemRenderer recycling, so generally only the currently visible itemRenderers actually exist, and are therefore the ones that actually need updating.

The following works for Spark list-based controls:

for ( var i:int=0; i< sparkList.dataGroup.numElements; i++ )
            {
                var element:UIComponent = sparkList.dataGroup.getElementAt( i ) as UIComponent;
                if ( element )
                    element.invalidateProperties();
                else
                    trace("element " + i.toString() + " wasn't there");

            }

If you've got 100 items, this will update the 10 visible ones and ignore the virtual rest.

If you're working with mx DataGrid, you might want to try a variant of this- but it doesn't use DataGroup / Spark virtualization so I don't have an answer for you off the top of my head.

P.S. I'm putting the finishing touches on a completely Spark-based DataGrid, I'll post the link when I'm done.

Yarin