PDA

View Full Version : Progamatically select TreeNode after adding it to the tree



forumuser1080
30 Jun 2011, 5:19 PM
I have a menu in which users can add a node to the tree. When a node is added I want to select it in the tree. My tree is sorted via a TreeSorter

I have tried:


var node = parentNode.appendChild({.....});

node.select();
My problem with this solution is that the node is inserted (usually at the bottom of the tree) and selected. This selection causes my scroll bar on the tree panel to scroll to the bottom. An instant later the tree is sorted and my selected node gets moved to the top of the tree, but the scroll bar remains at the bottom.

I looked but I did not see any events for the TreeSorter that tell me when the tree is done sorting.

I have also tried:



parentNode.on('append', function(tree, thisNode, node, index) {
// Select the newly appended node
node.select();
}, this, {single: true}); // single is true so that I only listen for the event once

var node = parentNode.appendChild({.....});

node.select();
This does not work because the append event fires and the node has not yet been rendered so I get an exception. If the node has not yet been rendered then it has not been sorted so even if I was able to select it I would still have the same problem as above.

Does anyone else have any ideas that I might be able to try?

Thanks

skirtle
30 Jun 2011, 6:38 PM
Had a quick look at the code for treesorter and I agree this looks awkward. If you take a look yourself you'll see that all treesorter does internally is call the sort() method on the parent node and no events are fired by either class. Perhaps you could call sort() manually before you select the node?