2

I'm trying to traverse all of the nodes in my tree panel. The problem is that if I don't expand a node before calling node.eachChild(), the node thinks that it doesn't have any children. (Even if it does)

If you look at my jsfiddle, click the Traverse button without expanding any nodes and it will only show the root node + its three child nodes. Now if you go back and expand all the child nodes, close them then click the button again it shows you all of the nodes.

http://jsfiddle.net/sQ97F/

How can I make my tree panel load all of the child nodes so that it goes through all the children right after onReady?

Note: I also don't want the nodes expanded in the onLoad() so hacking it up to use tree.getRootNode().expand() isn't a good solution.

Grammin
  • 11,808
  • 22
  • 80
  • 138

1 Answers1

1

Adding loader: new Ext.tree.TreeLoader({ preloadChildren: true }) to the TreePanel config should work.

new Ext.tree.TreePanel({
    renderTo: Ext.getBody(),

    loader: new Ext.tree.TreeLoader({ preloadChildren: true }), //New Config


    id: 'mainTree',
    title: 'Packages',
    useArrows: true,
    autoScroll: true,
    containerScroll: true,
    frame: true,
    rootVisible: false,
    root: rootNode,
    buttons: [traverse]
});
Andrew Lapham
  • 478
  • 4
  • 7
  • Hmmm when I add a dataUrl (which links to generated json) to the treeloader config it still doesn't preload the children, any ideas? – Grammin Aug 22 '13 at 21:38
  • Unfortunately I think that's how it works in ExtJS 3. You can either extend the TreeLoader or TreePanel and try to achieve the desired result, or load the JSON and create an AsyncTreeNode manually instead of using the dataUrl. If I have some time I will take a look at the Tree source code and see what it would take to load the whole thing. – Andrew Lapham Aug 23 '13 at 12:16