PDA

View Full Version : Tree with mixed type of nodes



Parag
1 Aug 2007, 6:33 AM
Hi,
I need help on tree widget. Can I create a tree with AsyncTreeNode(s) and TreeNode(s) at same level? Requirement is like in tree there are few nodes which needs to be loaded using AJAX but others I want to render directly. When I create one node as AsyncTreeNode, all children below are also AsyncTreeNode by default. I could not find any configuration property using which I can set the node to be of TreeNode type.
Thanx,
Parag

Grimsk
1 Aug 2007, 6:43 AM
The example in the doc do the trick with the button new album
http://extjs.com/deploy/ext/examples/tree/organizer.html

Parag
2 Aug 2007, 7:01 AM
Thanx Grimsk for the response.
I did it by extending TreeLoader and overriding createNode function as below -

Ext.tree.TVTreeLoader = function(config){
Ext.tree.TVTreeLoader.superclass.constructor.apply(this, arguments);
};
Ext.extend(Ext.tree.TVTreeLoader, Ext.tree.TreeLoader, {
// private
createNode : function(attr){
// apply baseAttrs, nice idea Corey!
if(this.baseAttrs){
Ext.applyIf(attr, this.baseAttrs);
}
if(this.applyLoader !== false){
attr.loader = this;
}
if(typeof attr.uiProvider == 'string'){
attr.uiProvider = this.uiProviders[attr.uiProvider] || eval(attr.uiProvider);
}
var treenode = null;
if (attr.leaf)
treenode = new Ext.tree.TreeNode(attr);
else {
// setting childNodes array in response object
if (attr.childNodes) {
treenode = new Ext.tree.TreeNode(attr);
var len = attr.childNodes.length;
for(var i = 0; i < len; i++){
var n = this.createNode(attr.childNodes[i]);
if(n){
treenode.appendChild(n);
}
}
} else {
treenode = new Ext.tree.AsyncTreeNode(attr);
}
}
return treenode;
}
});