Search code examples
apache-flexactionscriptadvanceddatagrid

Get The Items Under An Expanded Node in AdvancedDataGrid


Is there a way to get the items which are under an expanded ADG tree node?

Given the sample tree node:

- Atlantic
    Celtics
    Nets
    Knicks
    Sixers
    Raptors
+ Central
+ SouthEast
+ SouthWest
+ NorthWest
+ Pacific

I am planning to capture the data in the ADG's itemOpen event.

private function myADG_ItemOpen(event:AdvancedDataGridEvent) :void
{
  // What codes do I put here to get the following teams:
  // Celtics, Nets, Knicks, Sixers, Raptors
}

Update: I managed to pull off some codes that somehow provides me an object containing the teams:

var ihd:IHierarchicalData = IHierarchicalCollectionView(myADG.dataProvider).source;

    if(ihd.hasChildren(evt.item))
    {
      var objGetChildren:Object = ihd.getChildren(evt.item);
      var dataString:String = ObjectUtil.toString(objGetChildren);

      // From here, I am able to parse the dataString to an array, where I am able to get the team name.
    }

Solution

  • You can get the ADG from the AdvancedDataGridEvent and then you can try to cast its dataProvider to an IHierarchicalCollectionView. If that worked you can use it to get the children of the opend node.

    private function myADG_ItemOpen(event:AdvancedDataGridEvent):void
    {
        var grid:AdvancedDataGrid = AdvancedDataGrid(event.currentTarget);
        var dataProvider:IHierarchicalCollectionView = grid.dataProvider as IHierarchicalCollectionView;
    
        if (dataProvider && event.item)
        {
            var children:ICollectionView = dataProvider.getChildren(event.item);
    
            if (children)
            {
                // do something with the children
            }
        }
    }