View Full Version : 3.2 - Initial Load Of Tree Panel

16 Apr 2010, 10:16 PM
I am trying to load a TreePanel which is partialy dynamic in that when the TreePanel is created the root node and its level 1 children and level 2 children are already known. When a child node (level 2) is then expanded I would like to have the tree call out to an API to get it's children...Level #3.
The problems is that the tree is loading, however the root node is not expanded, and when clicked seems to call out to load it's Level 1 children. How do I get the tree loaded initial and have it's children expanded automatically (level 1 and 2)?

When the tree is created, there is an XML document element which contains its initial hierarchy (root->level#1->Level #2). The XML looks as follows:

<root id="1234" name="My Root" > -- Root
<Group id="ABC" name="Group 1" > -- Level 1
<node id="5001274" name="Child One" /> -- Level 2
<node id="5000815" name="Child Two" /> -- Level 2

Below is JavaScript To Load Initial Tree:

function loadTreeNode(treenode, xmlelement) {

var objId = element.getAttribute('id');
var objText = element.getAttribute('name');
var key = objId = '' ? objText : objId;
var icon = element.nodeName == 'Group' ? 'folder' : objType;

var top = new Ext.tree.TreeNode({
id: key,
text: objText,
icon: icon,
expanded: true
// recursivley loop through children

for (var i=0; i<element.childNodes.length; i++) {
loadTreeNode(top, element.childNodes[i]);


loadTreeNode(getTopRootXMLFunction(), new Ext.tree.RootTreeNodeUI({

id: 'root',
text: 'My Top Root',
draggable: false

Any idea how to have the tree panel initialized with an initial set of nodes, and dynamically expand the remaining children?