Search code examples
apache-flexadvanceddatagrid

In flex, can I expand a row of the AdvancedDataGrid without using HierarchicalData?


The subject pretty much asks it all. I am a newbie to flex, and I am trying to do something similar to this example http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_10.html. How do I get this working without HierarchicalData?


Solution

  • You also have the option of using a GroupingCollection. This essentially will group like items based upon a common attribute of those items. If you're on Flex 4, use the GroupingCollection2, it has several performance enhancements.

    <mx:AdvancedDataGrid id="adg" initialize="{gc.refresh()}"
                             width="100%" height="100%">
            <mx:dataProvider>
                <mx:GroupingCollection id="gc">
                    <mx:Grouping>
                        <mx:GroupingField name="type" />
                    </mx:Grouping>
                    <mx:source>
                        <s:ArrayCollection>
                            <fx:Object name="Shaggy" type="dog" />
                            <fx:Object name="Scooby" type="human" />
                            <fx:Object name="Fred" type="human" />
                            <fx:Object name="Thelma" type="human" />
                            <fx:Object name="Scrappy" type="dog" />
                        </s:ArrayCollection>
                    </mx:source>
                </mx:GroupingCollection>
            </mx:dataProvider>
            <mx:columns>
                <mx:AdvancedDataGridColumn dataField="name" headerText="Name"/>
            </mx:columns>
        </mx:AdvancedDataGrid>
    

    Dont forget to call gc.refresh() on initialize and also every time your data provider is updated.

    public function set theDataProvider(ac:ArrayCollection):void{
        _theDataProvider = ac;
        gc.refresh();
    }