PDA

View Full Version : Tree: Get child without expanding node



karma
12 Sep 2008, 6:39 AM
Greetings again,

How do I get (to set properties) a child from a collapsed node in a Ext.tree.TreePanel without expanding the node ? If I don't expand it the tree.getNodeByID returns "null or not an object".


TYA

Animal
12 Sep 2008, 7:06 AM
If the node's children are loaded from a configured children Array, use preloadChildren: true in the config of the TreeLoader.

If the node's children are to be loaded from the server ask the TreeLoader to load them: http://extjs.com/deploy/dev/docs/?class=Ext.tree.TreeLoader&member=load

karma
12 Sep 2008, 7:49 AM
If the node's children are loaded from a configured children Array, use preloadChildren: true in the config of the TreeLoader.

If the node's children are to be loaded from the server ask the TreeLoader to load them: http://extjs.com/deploy/dev/docs/?class=Ext.tree.TreeLoader&member=load

I guess something like:



tree.getLoader().load(new Ext.tree.AsyncTreeNode({ id: gsel.get('id') }),
function() {
rsel.removeChild(tree.getNodeById(gsel.get('id')));
}
);


should work, but no. I'm using a personalized tree loader (found on the web under the name of JayrockTreeLoader), but I don't think that would interfere with this statement, as the only thing my tree loader analyses is the node's ID.


Thank you for your quick reply!

Animal
12 Sep 2008, 7:53 AM
load() loads the children of an existing node. So you call it on the node who's child nodes you wish to access.

Obviously unless they are already loaded - you only need to load them once.

karma
12 Sep 2008, 8:14 AM
load() loads the children of an existing node. So you call it on the node who's child nodes you wish to access.

Obviously unless they are already loaded - you only need to load them once.

That's it! Thank you very much.

twinkle
25 Sep 2008, 5:20 AM
Karma can you post your solution here.Because my json file on tree loaded everytime and I could not handle with using id. I want you to see your code

karma
25 Sep 2008, 8:36 AM
Karma can you post your solution here.Because my json file on tree loaded everytime and I could not handle with using id. I want you to see your code

For example, setting a node's text before it has been shown on tree



tree.getLoader().load(thenodetoload, function() {
tree.getNodeById('the wanted node's id').setText('some text');
});


thenodetoload is the parent node of the node with id='the wanted node's id'. I couldn't understand your problem. If you post some of your 'problem zone' I might be able to help you further.

twinkle
25 Sep 2008, 11:52 PM
Thanks I understand now...

keckeroo
10 Nov 2008, 11:19 PM
Is there not an easy way to tell the tree to just load all node/children data during the initialization of the tree ?

I have a tree which *all* initialization data is sent from the server so the entire tree should have all the nodes from square one. However until all the children nodes have been expanded at least once i cannot access the children.

for example:



loader: new Ext.tree.TreeLoader({
preloadChildren: true,
dataUrl: '/ica/icaMessenger.HeartBeat.php?cmd=SYN'
}),



and data sent from server :



[{ id: "icaMessengerGroup-Online", username: "1", text: "Online (4)", leaf: false, expanded: true, singleClickExpand: true,
children: [
{ "id": "icaMessenger-1181", text: "xtd1234", leaf: true, iconCls: "ux-Online" },
{ "id": "icaMessenger-1133", text: "keckeroo", leaf: true, iconCls: "ux-Online" }
]},

{ id: "icaMessengerGroup-Offline", text: "Offline (11)", leaf: false, expanded: false, singleClickExpand: true,
children: [
{ "id": "icaMessenger-1161", text: "Simpleboxers", leaf: true, iconCls: "ux-Offline" },
{ "id": "icaMessenger-1180", text: "Sparkey", leaf: true, iconCls: "ux-Offline" },
{ "id": "icaMessenger-1197", text: "chuffy", leaf: true, iconCls: "ux-Offline" }]}]


You can see by the node data above that the 'online' list is expanded upon render and the offline is closed.

Unfortunately i want to be able to access the 'offline' children even if the node has not been expanded......

Yeah - i'm kinda stuck here ....

Thanks!

Kevin

Animal
10 Nov 2008, 11:50 PM
It should load them all. Try stepping through with the debugger to see why it's not.

keckeroo
11 Nov 2008, 10:21 AM
Could you point me in the right direction with a debugger ? Firebug and then what ? Just FYI ... I put this in the TreePanel ...



tools:[{
id:'refresh',
on:{
click: function(){
buddyPanel.getRootNode().cascade(function(){alert(this.id);});
}
}
}],


and yep - when i click on the refresh icon it 'alerts' all nodes EXCEPT the ones in the unexpanded 'offline' node. Yet low and behold - once i expand that node and click the 'refresh' icon again - voila - they all appear - even after i collapse the 'offline' node. It seems to always need an 'expand' to make the nodes 'visible' :-(

Kev

Animal
11 Nov 2008, 12:55 PM
Use ext-all-debug.jsin your page.

In your IDE, you'll have a project "ext" which encapsulates the Ext installlation directory, so bring in Ext.tree.TreeLoader, and examine it.

so you find



load : function(node, callback){
if(this.clearOnLoad){
while(node.firstChild){
node.removeChild(node.firstChild);
}
}
if(this.doPreload(node)){ // preloaded json children
if(typeof callback == "function"){
callback();
}
}else if(this.dataUrl||this.url){
this.requestData(node, callback);
}
},


And think ahah! That's the method that does stuff!

So, switch into Firefox, bring up ext-all-debug.js in the Script tab, and search for that. Type some uniq string into the search box like "doPreload : function(node){"

It should find it for you. So click in thge margin to set a breakpoint, then load your tree. It will break there loading the root node, and you should be able to follow the logic through. If it's all loaded from one object with no Ajax for each node, it should just plod through and load everything.

keckeroo
11 Nov 2008, 1:59 PM
Yeah - i think i found the problem - it has to do with nodeHash ... it appears this is where getNodeById retrieves the nodes - but a node is NOT inserted into the tree's nodeHash until the node is expanded. Mind you - that was just glacing at the code - someone more in tune with the inner workings of Extjs should be able to confirm my suspicions.

Thanks Animal for your help....

My temporary solution is to load the tree with all nodes expanded and then collapse them all after the load (before the show) and expand just the first node.

Kev