开发者

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

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

开发者_StackOverflow中文版

and 1 line is available in this one

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

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

thank you!


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜