accessing subnodes in TreeView from javascript

  • Thread starter Thread starter Johan Åhlén
  • Start date Start date
J

Johan Åhlén

Hi,

Does anybody have any idea how to access child nodes in a TreeView
without using postbacks?

For example: in the subtree below I want to disable nodes B, C and D
when A is checked (and enable them again when A is unchecked):

Subtree:
[ ]A---[ ]B
|----[ ]C
|----[ ]D

I want to do this entirely in javascript. Any idea how to access the state
of the child nodes from the eventhandlers?

Thanks for any help!

Johan

---
Johan Åhlén
Bostadstips Sverige AB
Email: (e-mail address removed) <-- remove NOSPAM to email me
Web: http://www.bostadstips.com
Tel +46 31 842500
 
Hi again,

Accessing the child nodes wasn't that much of a problem. The bigger problem
was
disabling them, which required (from what I have found) making changes in
the
control itself, to support a new attribute - "disabled".

Here is the the resulting code:

Add eventhandler:
oncheck="javascript: if (this.clickedNodeIndex != null)
__disableChildNodes(this);"

// Select and disable all child nodes under the recently clicked node
function __disableChildNodes( tree )
{
var node = tree.getTreeNode(tree.clickedNodeIndex);
var state = node.getAttribute('checked');

__setChildNodesState( node, state );
}

function __setChildNodesState( node, state )
{
var children = node.getChildren();

if ( children[0] != undefined )
{
for (var i = 0; i < children.length; i++)
{
children.setAttribute('checked',state);
children.setAttribute('disabled',state);
__setChildNodesState( children, state );
}
}
}
 
Back
Top