1

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???

mwigdahl
  • 16,268
  • 7
  • 50
  • 64
Eric Belair
  • 10,574
  • 13
  • 75
  • 116

3 Answers3

1

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

dirkgently
  • 108,024
  • 16
  • 131
  • 187
1

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">
    <mx:dataProvider>
        <mx:HierarchicalData source="{__model.parentItems}" />
    </mx:dataProvider>
</mx:AdvancedDataGrid>
Eric Belair
  • 10,574
  • 13
  • 75
  • 116
0

Try

IHierarchicalCollectionView(__model.myHierarchicalData).refresh();
sth
  • 222,467
  • 53
  • 283
  • 367
mike
  • 1