PDA

View Full Version : TreePanel - load all nodes at once?



bbxx
22 Aug 2009, 5:50 PM
I have a simple TreePanel that is loading nodes from a php page. Problem is, it only loads the nodes when a folder item is clicked on. I want my tree to load all of the data and be fully expanded right away. Is there an easy way to do this? I have looked around and all I can find are examples where they load one level at a time.



var calendarTree = new Ext.tree.TreePanel({
width: 550,
height: 300,
rootVisible:false,
autoScroll:true,
title: 'Calendar Detail',

loader: new Ext.tree.TreeLoader({
dataUrl :"get-calendar-nodes.php"
}),

root: new Ext.tree.AsyncTreeNode({
text:'Tasks'
})
});

bbxx
22 Aug 2009, 8:02 PM
I just discovered the children attribute by looking through the source code of extjs.

And then I also discovered the expandAll function, which I call from the "load" event.

Problem solved!

Condor
23 Aug 2009, 12:18 AM
The expandAll isn't required when you put expanded:true in the node attributes (either in the baseAttrs or returned by your server).

bbxx
23 Aug 2009, 9:51 AM
The expandAll isn't required when you put expanded:true in the node attributes (either in the baseAttrs or returned by your server).

Even better! Thanks

njw
22 Oct 2009, 5:46 AM
Can this be done without hitting the server for each node that is expanded?

My first hit loads all the data (complete structure of children) - so I dont want to hit the server more than once.

Condor
22 Oct 2009, 7:30 AM
Have your server return all children and configure the loader with preloadChildren:true.

njw
22 Oct 2009, 7:38 AM
Have your server return all children and configure the loader with preloadChildren:true.

I've tried this option, but using fiddler I still see a server hit for each node as its expanded. I'm using a very simple Tree panel, with the following loader:



loader: new Ext.tree.TreeLoader({
dataUrl: serverUrl,
baseParams: { loadfrom: 0 },
preloadChildren: true
})

Condor
22 Oct 2009, 7:42 AM
Add nodeType:'node' or loaded:true to the non-leaf node attributes.

njw
22 Oct 2009, 8:07 AM
Add nodeType:'node' or loaded:true to the non-leaf node attributes.

Adding loaded: true to non-leaf nodes prevented additional nodes/children being loaded into the tree, only the root node/first level of nodes was loaded.

I tried nodeType: 'node' on the non-leaf nodes, and it made no difference.

So, I tried adding nodeType: 'node' to the root node, it made no difference. Adding loaded: true to the root node prevented any nodes being loaded (the tree was empty) (:|

thanks for the help so far

razvanioan
10 Sep 2014, 3:08 PM
I'm also interested in this behaviour (but in ExtJS 5):

- have all nodes on all levels loaded at once (with children / leaf options set correctly)
- only root node to be expanded on init
- render correctly all the nodes
- do NOT send another request to server on folder expand !

preloadChildren not found anymore (no loader for tree now)
loaded / nodeType have no effect

couldn't find in documentation anything about lazuFill on TreeStore (found on some example) no effect either...

razvanioan
10 Sep 2014, 11:32 PM
I was pulling my hair out, but found the cause / resolution for my case (ExtJS 5)

In my returning JSON I was sending "children" nodes as well, BUT...

On my tree proxy I had defined rootProperty:"data" (like I have for all my stores) although for this tree I have changed the PHP to return directly only the nodes....

Removing rootProperty resolved my problem, tree didn't send any other request to server...

It would have worked as well if instead of "children" I would have put "data" in the JSON: http://stackoverflow.com/questions/18931443/extjs4-2-1-load-json-to-treepanel-fails#answer-18960896