PDA

View Full Version : TreeNode not expanding



mitchellsimoens
9 Apr 2010, 9:01 AM
I am trying to dynamically add nodes to a TreePanel and I can get one level and it all works but when I add another level and try to expand the node it does not work.


-Root
--Level 1
---Level 2 <-- Will not show

Test case:


new Ext.tree.TreePanel({
title : "Databases",
id : "dbTree",
width : 200,
autoScroll : true,
root : new Ext.tree.TreeNode({
text : "Root Node",
expanded : true
}),
rootVisible : true,
renderTo : Ext.getBody()
});

var node = Ext.getCmp("dbTree").getRootNode().appendChild({
text : "Mitch"
});

node.appendChild({
text : "Hello"
});

CrazyEnigma
9 Apr 2010, 9:04 AM
Did you specify?


leaf: false

mitchellsimoens
9 Apr 2010, 9:06 AM
believe it is by default but yes I added it and still no

In action: http://www.simoens.org/test/

mitchellsimoens
10 Apr 2010, 5:26 PM
Got it to work by adding

nodeType: "node"


new Ext.tree.TreePanel({
title : "Databases",
id : "dbTree",
width : 200,
autoScroll : true,
root : new Ext.tree.TreeNode({
text : "Root Node",
id : "dbTreeRoot",
expanded : true
}),
rootVisible : true,
renderTo : Ext.getBody()
});

var node = Ext.getCmp("dbTree").getRootNode().appendChild({
text : "Mitch",
nodeType : "node"
});

node.appendChild({
text : "Hello",
nodeType : "node"
});

Zerogiven
11 Apr 2010, 12:53 AM
Hmm, i never used the "nodeType" attribute, but if it works i think it's ok for you, however here an example how i did append Nodes to a tree (which are still expandable)


// newChildConfig for node without children
newChildConfig = {
leaf: true,
expandable: false
};

// newChildConfig for node with children (expandable == true)
newChildConfig = {
leaf: false,
expandable: true
};

newChildConfig.id = newId; // a unique id in the tree
newChildConfig.text = "New";

var newChild = new Ext.tree.TreeNode( newChildConfig );
myTree.getRootNode().parentNode.appendChild( newChild );

With the second conf. the newChild is expandable if it has childrens.

cheers