PDA

View Full Version : More tree questions



seldon
8 Jan 2007, 4:50 AM
I have a couple more short tree questions:

How can i select the first child of the root of a tree? I tried:



tree.getSelectionModel().select(root.childNodes[0]);

but that doesnt seem to work. (there doesnt seem to be a node method getFirstChildNode, perhaps it is an idea to include such a method?)

How to make a node unselectable?

I tried adding the param selectable: false to the node, but that doesnt seem to work :) I looked in the TreeSelectionModel class and it seems such a param isnt supported. Could i add it myself?

How to get those icons that inform the user if an element can be dropped at the place that he or she chooses?


I have only the following method:


tree.on('nodedragover', function(e){
if(e.point == 'above' && e.target.attributes.parent == e.source.attributes.parent) return true;
return false;
});


Perhaps i must add more events?

How to refresh/reload a tree after a node has been added on the server-side ?
I cant seem to find any refersh or reload methods in either the treePanel or the TreeNode class. I tried


tree.root.loaded=false;
tree.root.expand(true);

This works, but isnt the nicest way i guess. Moreover, it produces my bug/problem of having the tree twice as described in another post.

Thanks already (again!)

Seldon

jack.slocum
8 Jan 2007, 11:23 AM
there doesnt seem to be a node method getFirstChildNode, perhaps it is an idea to include such a method?

It's the same as DOM: root.firstChild

tree.getSelectionModel().select(root.childNodes[0]); that code should work as well. Did you verify that there is a root.childNodes[0]?

How to make a node unselectable?

It's not currently built in. There should be a "beforeselect" event I presume. For now you could add a selectable:false attribute and use this small function:


var sm = tree.getSelectionModel();
sm.select = sm.select.createInterceptor(function(node){
return node.selectable !== false;
});

How to get those icons that inform the user if an element can be dropped at the place that he or she chooses?

Can you explain this one a little more?

How to refresh/reload a tree after a node has been added on the server-side ?

You could try:

while(root.firstChild){
root.removeChild(root.firstChild);
}
root.loaded = false;
root.expand(true);

reignman
8 Jan 2007, 11:30 AM
How can i select the first child of the root of a tree? I tried:


root.firstChild


How to make a node unselectable?

in the config use attribute 'disabled:true'

How to get those icons that inform the user if an element can be dropped at the place that he or she chooses?


hmmm haven't tried yet

How to refresh/reload a tree after a node has been added on the server-side ?
I cant seem to find any refersh or reload methods in either the treePanel or the TreeNode class. I tried

you can build your own statesever with CookieProvider....
or why don't you just add new nodes on the fly?
with a call like this : node.parentNode.insertBefore(newnode,node);

seldon
8 Jan 2007, 12:00 PM
Hi,

Thanks for the answers Jack & Reignman. It helped me already a lot! It would be nice if the insertBefore method automatically made a call to the server informing it of the insertion. I guess, now i must listen to the afterinsert event perhaps to do it myself?

Seldon

seldon
8 Jan 2007, 3:02 PM
Another question,

How can i have the tree select the first child of the root element, once the tree is loaded ?

I tried,

tree.getSelectionModel().select(tree.root.firstChild);

But that didnt work ( iguess because the root child nodes probably arent fully loaded yet)

Thanks!

Seldon

jack.slocum
8 Jan 2007, 5:41 PM
var loader = ...
var tree = ...

var f = function(){
tree.getSelectionModel().select(tree.root.firstChild);
loader.removeListener(f);
}
loader.on('load', f);