Flex: Expand AdvancedDataGrid Tree Column programmatically

19,101

Solution 1

AdvancedDataGrid has an expandItem() method too:

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

Solution 2

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);
}

Solution 3

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.

Solution 4

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();
    }
Share:
19,101
CodeMonkey
Author by

CodeMonkey

Updated on June 08, 2022

Comments

  • CodeMonkey
    CodeMonkey about 2 years

    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.