What is the difference between Children and dataProvider Elements in a Flex DataGrid?
Sean was having some trouble with the number of children in the dataProvider of a DataGrid. Here was his question:
Is there a property other than numChildren that will return the actual number of children in the DataGrid instead of only the visible number of children?
The numChildren property returns the number of children (AKA itemRenderer objects) in the DataGrid. Was was getting exactly what he was asking for. Unfortuantely, he was asking for the wrong thing. What he wanted was the number of elements in the dataProvider; which is a completely different number.
The DataGrid (and List, and probably other similar type components) only creates children (rows) based on what is shown on the screen. As you scroll through a DataGrid, the children (rows) are recycled. Instead of creating a new row for each element, it changes the content in an already existing one. This is done for performance reasons. If you have a list of 100 images, for example, but are only displaying 6 images you wouldn't want the Flash Player to render all 100 images.
To get the number of elements in the dataProvider, you need to go back to the dataProvider. If it's an ArrayCollection, you can use the length. Something like this would work DataGrid.dataProvider.length.
The difference between children and dataProvider elements was not intuitive to Sean. I guess if he really wanted to use the numChildren to get the value he wanted, he could extend the DataGrid and override the property. However, that would be inconsistent with how numChildren is handled in the rest of the framework. It refers to visual elements, not data elements.
Cookie Crisp for breakfast, I can't wait.




There are no comments for this entry.
[Add Comment]