PDA

View Full Version : Add TreeNode dynamically



mtdave
27 Jan 2011, 3:35 PM
Hi, I am trying to add TreeNode(s) to an existing tree in a TreePanel dynamically. I have not had luck getting them to render in the tree.

I create the TreePanel similar to the following and add it to a Window. This part is working:



var treeGen;

treeGen = new Ext.tree.TreePanel({
id: 'treeGen',
height: 250,
useArrows:true,
autoScroll:true,
animate:true,
enableDD:false,
containerScroll: true,
rootVisible: true,
frame: true,
root: {
//nodeType: 'async',
text: 'Layers',
draggable: false,
allowChildren: true,
expanded: true,
children: [{
text: 'Layer 1',
leaf: true
}]
},
Then I need to be able to add additional TreeNode(s) on the fly and have them render. I have tried lots of variations of the following without success yet.



function loadTree() {
var rootNd = treeGen.root;


var newNd = new Ext.tree.TreeNode({
leaf: true,
text: "Layer 2"
});

rootNd.appendChild(newNd);
//rootNd.expand();

treeGen.update();


}
Anyone have the trick?

Thanks

mtdave
28 Jan 2011, 7:17 AM
bump

mtdave
31 Jan 2011, 9:41 AM
Hi, I still haven't been able to figure this out. Is it possible to add a TreeNode to an existing TreePanel tree? It seems like I almost have it but I've been unable to get the TreeNode to render after I append it. Any help appreciated.

Thanks, Dave

mschwartz
31 Jan 2011, 10:40 AM
I do this sort of thing all the time. The only difference I can see in your code is how you define root node. Instead of a config object, try new Ext.tree.TreeNode({ config options }) and see if that works. It may be doing an async type node by default which isn't working for you.