PDA

View Full Version : Loading TreePanel from a data store



yousefomar
6 Nov 2009, 3:18 PM
Hello expets,
Here is the scenario, I have a data store that has a proxy to make ajax call to load some data from the server, and I want to show this data in a treePanel.
so I added a store listener to the "load" event to trigger a function that reads the store and adds its data to the tree.
for some reason, in firebug I see that the tree has 5 items, but when I expand the tree I get the spinning icon but the tree never loads.

please help

here the code:



Cat.ZoneTree = Ext.extend(Ext.tree.TreePanel, {
initComponent: function() {
this.addEvents(
'dashboardselected',
'zoneselected',
'assetselected'
);

// add Store Listener
this.zoneStore.on('load', function(){
this.loadTreeData();
}, this);

Cat.ZoneTree.superclass.initComponent.apply(this, arguments);
},
loadTreeData : function(){
var treeChildren = [];
this.zoneStore.each(function(record){
// create a tree item
var zone = {
text: record.get('name'),
iconCls: 'zone-icon',
children: [],
zone: record
};
// add the item to the array
treeChildren.push(zone);
}, this);

// add the array of items to the tree
this.add(treeChildren);
this.doLayout();
},
useArrows: true,
autoScroll: true,
loader: new Ext.tree.TreeLoader({preloadChildren: true}),
root: {
text: 'Dashboard',
iconCls: 'world-icon',
dashboard: true
}
});

Ext.reg('cb.tztree', Cat.ZoneTree);

mbenothmane
6 Nov 2009, 4:59 PM
Make sure the spinning node has leaf property set to true (leaf=true)

yousefomar
6 Nov 2009, 5:10 PM
it's the root node, it can't be leaf:true, otherwise tree wouldn't expand

Condor
6 Nov 2009, 11:08 PM
Configure your root with nodeType:'node' (=TreeNode) or with loaded:true (= loaded AsyncTreeNode).

yousefomar
7 Nov 2009, 9:40 AM
Hi Condor,
I tried both nodeType:'node' and loaded:true, both made the tree un-expandable !!
any idea?

yousefomar
8 Nov 2009, 10:13 AM
any advice here please, I just need to load a tree using a data store

thank you