martin
martin

Reputation: 989

Refresh Datagrid with Hierarchical Data

how can I refresh the displayed data in a Datagrid when the underlying ArrayCollection changes?

<nmoschitz:dataProvider>
    <mx:HierarchicalData source="{arrCol_groupedData}"
         childrenField="accounts"/>
</nmoschitz:dataProvider>

Calling a simple refresh (like with a simple arraycollection as a dataprovider, or with a refresh on the Grouping Collection) does not work. Also re-assigning the arrayCollection to the Hierarchical Data and then assigning this one again to the Datagrid does not work (even with calling invalidateProperties() or validateNow()).

Any ideas? Someone suggested to extend HierarchicalData and throw a manual change event, but that seems very akward to me.

Thanks, Martin

Upvotes: 0

Views: 2748

Answers (4)

zawhtut
zawhtut

Reputation: 8561

Just expand the root node and close again programmatically will refresh the UI.

                   if(!dGGrid.isItemOpen(itemData)){
                        dGGrid.expandItem(itemData,true);
                        dGGrid.expandItem(itemData,false)
                    }else{
                        dGGrid.expandItem(itemData,false);
                        dGGrid.expandItem(itemData,true);
                    }

Upvotes: 0

Rishi
Rishi

Reputation: 11

You could try refreshing the arrayCollection and then calling invalidateList() on the grid

Upvotes: 1

Mike Sickler
Mike Sickler

Reputation: 34461

You can extend HierarchicalData and override the source property setter to throw a CollectionChange event:

package mypackage
{
import mx.collections.HierarchicalData;
import mx.events.CollectionEvent;
import mx.events.CollectionEventKind;

public class ModifiedHierarchicalData extends HierarchicalData
{
override public function set source(value:Object):void
{
super.source = value;
var event:CollectionEvent =
new CollectionEvent(CollectionEvent.COLLECTION_CHANGE) ;
event.kind = CollectionEventKind.RESET;
dispatchEvent(event);
}
}
}

Upvotes: 0

martin
martin

Reputation: 989

I reassigned the whole hierarchical data to the datagrid. However, only the arraycollection needs to be reassigned to the hierarchical data. This solves the issue.

Upvotes: 0

Related Questions