views:

1892

answers:

4

I have an AdvancedDataGrid (ADG) with a HierarchicalData dataProvider:

<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"
    dataProvider="{__model.myHierarchicalData}" 
    displayItemsExpanded="true" sortExpertMode="true" dropEnabled="true" 
    sortableColumns="false" draggableColumns="false" 
    resizableColumns="true" textAlign="left" defaultLeafIcon="{null}" 
    folderOpenIcon="{null}" folderClosedIcon="{null}"/>

When I initially set the HierarchicalData instance in the Model, it is displayed as expected:

function buildHierarchicalData(parentItems:ArrayCollection):void
{
    __model.myHierarchicalData = new HierarchicalData();

    __model.myHierarchicalData.source = parentItems;
}

parentItems is a Collection of ParentItem valueObjects:

package
{
    [Bindable]
    public class ParentItem
    {
        public var children:ArrayCollection;

        public var label:String;
    }
}

However, when I move child items from one parent to another (via drag-and-drop), the update is not visible, using this code:

function moveChildren(movedChildren:Array /* of ParentItem */):void
{
    parentItem.children = new ArrayCollection(movedChildren);
}

For some reason, however, this DOES work:

function moveChildren(movedChildren:Array /* of ParentItem */):void
{
    parentItem.children.source = movedChildren;
}

Why do I have to update the source of the ArrayCollection???

+1  A: 

See this. It is recommended to use a bindable ArrayCollection always when dealing with dataProviders.

dirkgently
Thanks for the link. I found my answer there.
Eric Belair
Actually, this made my code nicer, but didn't fix my problem. The class is bindable, but the dataprovider is still not updating correctly unless i update the source of the item.
Eric Belair
Wish you godspeed :)
dirkgently
A: 

Thanks to dirkgently for directing me to the answer. I am now eliminating the need for a HierarchicalData property in my model, and instead setting the Hierarchical dataProvider right in the MXML:

<mx:AdvancedDataGrid xmlns:mx="http://www.adobe.com/2006/mxml"&gt;
    <mx:dataProvider>
        <mx:HierarchicalData source="{__model.parentItems}" />
    </mx:dataProvider>
</mx:AdvancedDataGrid>
Eric Belair
A: 

Did you fine any answer for this. If yes then please let me know

Thanks

Sachin

sachin
yes, it is shown below - the one with the green check mark next to it - that means it's the correct answer.
Eric Belair
A: 

TRY IHierarchicalCollectionView(__model.myHierarchicalData).refresh();

mike