开发者

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

开发者 https://www.devze.com 2023-03-26 12:40 出处:网络
The subject pretty much asks it all. I a开发者_高级运维m 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_1

The subject pretty much asks it all. I a开发者_高级运维m 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?


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


You have to use a HierarchicalData object in order to achieve this behavior. What's the issue with using one? You should be able to pass an ArrayCollection to the constructor of the HierarchicalData object then set it's childrenField property and be good to go. If you need to operate on the original array collection you can either use the source of the HierarchicalData to get back the ArrayCollection or else you can store a separate reference to it. The HierarchicalData isn't a heavy weight object and just adds the things required to represent a hierarchy. For our case we wanted the expansion rows to have the same data as the original array collection row so we set the children property on the object to have a collection that contains the only the object itself, this way when the row is expanded the original data is passed along to the row expansion. Something like this is in our DTOs/Value objects: public var children:ArrayCollection;

children = new ArrayCollection([{parent:this}]);

setting it to have a new object with a property that is set to this works because if you just passed along this itself without wrapping an object around it and assigning it to a property then when you expand it would recursively try to expand the child as well. Then in the actual renderer in the set data function we check for the parent property and set the renderer's data property to be the parent of the data that was dropped in, this way everything can be bound to the data property within the renderer and all is well.

Let me know if this helps or if you are trying to achieve something different.

0

精彩评论

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

关注公众号