Search code examples
apache-flexactionscript-3flex3flex4advanceddatagrid

AdvancedDataGrid: how to tell how many rows are currently visible?


Does anyone know how to query an ADG (or its rows) to figure out how many rows are currently visible (i.e. not collapsed) when displaying different levels of a hierarchical collection?

In other words I'd like a function that tells me that 7 lines are visible in this view enter image description here

and 1 line is available in this one enter image description here

I assume this is simple but can't seem to find the right keyword anywhere.

thank you!


Solution

  • the openNodes property in view:IHierarchicalCollectionView seems to be what I was looking for. Passing the root node to this seems to do the trick. I'm sure there's a more elegant way to write this ;-)

    function recurse(o:Object):uint
    {
        // grab the general list, for commodity
        var view:IHierarchicalCollectionView = adg.dataProvider as IHierarchicalCollectionView;
    
        // I count as 1 if we're recursing through me
        var total:uint = 1;
    
        // check if I'm open
        for each (var e:Object in view.openNodes)
        {
            if (e == o)
            {
                // if so I need to add my children and their families
                for each (var c:Object in o.children)
                    total += recurse(c);
            }
        }
        // if not I'm done, just counting myself
    
        return total
    }
    

    Note: one thing I thought was interesting is that openNodes returns the list of open nodes, even if they are not visible like in the case of such nodes living inside a closed node.