Board Logo

How to Keep Only One Tree Open
Tolstoy - 6/25/2006 at 02:58 AM

My apologies if this is a newbie question; I'm only good enough with javascript to hack others' code and otherwise be dangerous, and I have read the forum looking for an answer.

I have a menu with several trees. This is due to the way I have the menu laid out within a vertical table with sections that are separated. To keep the menu(s) from expanding to a very long depth I would like to configure this so that only one tree is open at a time. I have tried to use the collapse_all() function within a SelectHandler, as well as a typical a href to the function, but nothing causes the trees or any of their nodes to collapse. I am not getting any errors in my Firefox Javascript console so at least I know that it isn't a typo.

Any help would be appreciated.

Lev


tigra - 7/10/2006 at 03:03 PM

Code:

var tree_tpl = {

... irrelevant part of the template structure skipped ...

'onItemSelect': 'onItemSelectHandler',
'onItemOpen' : 'onItemSelectHandler'


// make sure there is no comma after the last key-value pair
};

function onItemSelectHandler (o_item) {
for (var i = 0; i < TREES.length; i++)
if (i != o_item.o_root.n_id)
collapse_all(i);
return true;
}

// this one is copied from the documentation
function collapse_all (n_index, n_depth) {
var o_tree = TREES[n_index ? n_index : 0];
if (!n_depth) n_depth = 1;
if (!o_tree)
alert("Tree is not initialized yet");
var a_nodes = o_tree.a_nodes;
for (var i = a_nodes.length - 1; i >= 0; i--)
if (a_nodes.n_depth >= n_depth && a_nodes.open)
a_nodes.open(1, 1);
o_tree.ndom_refresh();
}


ikmps - 8/15/2006 at 06:26 AM

Hi to all
sorry for the question
I am trying to get the code working !!!
am i correct in thinking i add the bottom section to the bottom of the tree_tpl ??

if that is correct then i can't get it to work is there any think else i need to change

Thanks

Paul


tigra - 8/15/2006 at 11:01 AM

Make sure you use PRO version of the script.


ikmps - 8/16/2006 at 02:08 AM

Hi

It is the Pro version i am using

Paul


tigra - 8/16/2006 at 10:42 AM

Ok, then submit a support ticket attaching your code, we'll take a look.


danedev - 10/13/2006 at 06:45 AM

Hi

How would I implement that code in the dynamicly generated code, like in demo.asp and tree/items.asp?

Btw: Wonderful product, it was a breeze customizing it for use with my SQL database and structure because of the excellent asp/access-demo! :)

Best regards

Klaus


tigra - 10/13/2006 at 09:04 AM

The above modifications are in the template structure which is usually in the static file (tree_tpl.js) so there should be no difference if you generate the items structure (tree_items.[php/asp/whatever]) dynamically.


danedev - 10/17/2006 at 04:51 AM

It was a stupid copy+paste error in the collapse_all function, my mistake.

However, I am not getting the expected behaviour. The onItemSelectHandler fires as expected, but function collapse_all is never fired.

Added the event-handlers to tree_tpl.js
'onItemSelect': 'onItemSelectHandler',
'onItemOpen' : 'onItemSelectHandler'


Added functions onItemSelectHandler and collapse_all to demo.asp (and inserted alerts to make sure they actually fire).

Everything still works as before, and onItemSelectHandler is fired, but collapse_all is never fired.

I have tried just about everything I could think of, but I can't completely comprehend what is going on with the tree/javascript, could you take a look?

Any help will be greatly appreciated. :)

Regards

- Klaus


tigra - 10/17/2006 at 08:41 AM

collapse_all is called by onItemSelectHandler for the trees other than one generated the event. Since you have only one tree on the page and it's the only source of event, collapse_all is not called at all. It's probably something different that you need. For the one-opened-branch-at-a-time sample see the product documentation.


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/