[Dojo-interest] Help with Tree widget

Vikas Sasidharan vikas.sasidharan at tavant.com
Tue Dec 19 01:08:36 MST 2006


Hi,

Here is one way you can achieve (1):

//This code assumes that you are using the TreeSelectorV3 
// extension and that the selector is already created and
// available under the reference "selector".

dojo.event.topic.subscribe(selector.eventNames.select,
handleNodeSelect);

function handleNodeSelect(event) {
    var clickedNode = event.node;

    // We cancel out the select if it is a folder.
    if(clickedNode.isFolder) {
        dojo.widget.byId("selector").deselect(clickedNode);
        clickedNode.expand(); // If you want...
    }
}

The above code prevents selection of non-leaf (folder) nodes. Of course,
you can replace that check with whatever is relevant to your case.

This code was taken from my post
(http://www.nabble.com/forum/ViewPost.jtp?post=7495507&framed=y). Check
that out if you want more details.

As for (2), you are right - you can use a css based approach for that.
Here is how you can do it for the example that was mentioned above:

dojo.event.topic.subscribe(yourTree.eventNames.afterAddChild,
afterTreeNodeAdded);

function afterTreeNodeAdded(event) {
	var node = event.child;
	if(node.isFolder) {
	  dojo.html.addClass(node.contentNode, "unSelectableContent");
	}
}

// and in your css file
.unSelectableContent {
    ...
}

Rgds,
Vikas

-----Original Message-----
From: dojo-interest-bounces at dojotoolkit.org
[mailto:dojo-interest-bounces at dojotoolkit.org] On Behalf Of Dylan
Vanderhoof
Sent: Tuesday, December 19, 2006 1:50 AM
To: dojo-interest at dojotoolkit.org
Subject: RE: [Dojo-interest] Help with Tree widget

Nobody?  I can't be the only person who's tried to do this...

-D

> -----Original Message-----
> From: Dylan Vanderhoof 
> Sent: Thursday, December 14, 2006 12:40 PM
> To: dojo-interest at dojotoolkit.org
> Subject: [Dojo-interest] Help with Tree widget
> 
> 
I have a dataset (static) that is formed of nested divs.  

I'm able to create a tree fairly easily using the source found here:
http://archive.dojotoolkit.org/nightly/tests/widget/tree/test_Tree_0.htm
l

However, the problem I have is that I need some nodes to be selectable,
and some not.  

What I can't figure out is: 
1, how to disable selection on some nodes
2, how to have a visual difference (Make the text and link and let my
CSS take care of it?) between a selectable and non-selectable tree node.

Any suggestions?

Thanks,
Dylan
_______________________________________________
Dojo FAQ: http://dojo.jot.com/FAQ
Dojo Book: http://manual.dojotoolkit.org/DojoDotBook
Dojo-interest at dojotoolkit.org
http://dojotoolkit.org/mailman/listinfo/dojo-interest


More information about the Dojo-interest mailing list