actionscript-3apache-flexflex4

AdvancedDataGrid - access dataProvider


I have AdvancedDataGrid and I wanted to access dataProvider.getItemAt(i) in function in my view. I'm not getting any errors nor warning and the code is compiling, but when I run this function I get this error: Property getItemAt not found on mx.collections.HierarchicalCollectionView and there is no default value. Why can't I do this? I saw some samples ane people was using this function. This is how I call it:

var x:Object = _dg.dataProvider.getItemAt(i);

Solution

  • The AdvancedDataGrid's dataProvider is a generic object. That, basically, means the compiler will let any property/method access on it slide without issues.

    The HierarchicalCollectionView does not have a getItemAt() method, which is why you get the runtime error. The Hierarchical collection, by nature, contains nested elements I'm not sure how you'd access a single element using a single index.

    You probably want to use some form of getChildren() or getParentItem() method to get access to an individual node.

    The places where you saw getItemAt() work were most likely using an ArrayCollection.