3

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!

fred august
  • 1,109
  • 12
  • 31
  • To be more accurate, it's really the number of leaves that are expanded at any time. Visible is confusing in the sense that a leaf could be expanded but not currently on the screen because it's way down on a long list displayed on a short ADG). In other words, counting ItemRenderers currently being used on the ADG doesn't do the trick if the list is too long. – fred august Mar 08 '11 at 21:47

2 Answers2

2

You'll need to write a recursive function to iterate through your data and make use of the AdvancedDataGrid's isItemOpen(item:Object):Boolean function. Something like this:

countOpenItems(root : Object) : int {
 var openCount : int = 0;
 if (grid.isItemOpen(item)) {
  openCount++;
  for each (var child : Object in item.children) {
   openCount += countOpenItems(child);
  }
 }
 return openCount;
}

This example assumes each of your items has a property called children that can be iterated over.

note: This will return only the number of open items -- even in your second example this function will return 0. If you want to include open roots you'll have to account for them separately.

sean
  • 2,560
  • 3
  • 18
  • 21
  • thank you Sean. I implemented something at the same time, then found your answer which would have been of great help (isItemOpen is what I was looking for and calls openNodes, which is what I found in my search). I ended up posting my own answer as it seems to count things properly, but appreciate the help & upvoted you. – fred august Mar 09 '11 at 00:07
1

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.

fred august
  • 1,109
  • 12
  • 31