3

Does anyone know how to programmatically expand the nodes of an AdvancedDataGrid tree column in Flex? If I was using a tree I would use something like this:

dataGrid.expandItem(treeNodeObject, true);

But I don't seem to have access to this property in the AdvancedDataGrid.

Cœur
  • 37,241
  • 25
  • 195
  • 267
CodeMonkey
  • 300
  • 1
  • 6
  • 18

4 Answers4

5

AdvancedDataGrid has an expandItem() method too:

http://livedocs.adobe.com/flex/3/langref/mx/controls/AdvancedDataGrid.html#expandItem()

Eric Belair
  • 10,574
  • 13
  • 75
  • 116
5

Copy the sample found at the aforementioned url and call this function:

private function openMe():void
{
    var obj:Object = gc.getRoot();
    var temp:Object = ListCollectionView(obj).getItemAt(0);
    myADG.expandItem(temp,true);
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
slukse
  • 128
  • 3
2

Would like to add here that the AdvancedDataGrid, in spite of having an expandAll() method, has a property called displayItemsExpanded, which set to true will expand all the nodes.

For expanding particular children, the expandChildrenOf() and expandItem() methods can be used, as can be verified from the links given above.

LittleBobbyTables - Au Revoir
  • 32,008
  • 25
  • 109
  • 114
2

You could also open nodes by iterating through the dataProvider using a cursor. Here is how I open all nodes at a specified level:

    private var dataCursor:IHierarchicalCollectionViewCursor;

    override public function set dataProvider(value:Object):void
    {
        super.dataProvider = value;

        /* The dataProvider property has not been updated at this point, so call 
            commitProperties() so that the HierarchicalData value is available. */
        super.commitProperties();

        if (dataProvider is HierarchicalCollectionView)
            dataCursor = dataProvider.createCursor();
    }

    public function setOpenNodes(numLevels:int = 1):void
    {
        dataCursor.seek(CursorBookmark.FIRST);

        while (!dataCursor.afterLast)
        {
            if (dataCursor.currentDepth < numLevels)
                dataProvider.openNode(dataCursor.current);
            else
                dataProvider.closeNode(dataCursor.current);

            dataCursor.moveNext();
        }

        dataCursor.seek(CursorBookmark.FIRST, verticalScrollPosition);

        // Refresh the data provider to properly display the newly opened nodes
        dataProvider.refresh();
    }
Eric Belair
  • 10,574
  • 13
  • 75
  • 116