Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
392
Unchecking all nodes with Javascript
posted

I would like to make the UltraWebTree perform like a radio control in Javascript with a NodeChecked ClientSideEvent. Since there does not appear to be a built in way to do this I figure that Ill have to:

1. Remember what node was just checked.

2. Unselect all of the nodes.

3. Reselect the node that was just checked. 

Doing 1 & 3 are easy but I cant figure out how to do 2.  This doesnt work.  It gives a "too much recursion" error (even though the tree is tiny).

function TreeNodeChecked(treeName, id, bChecked)
{
  if (!bChecked)
    return;
 
  var node = igtree_getNodeById(id);
  var tree = igtree_getTreeById(treeName);
 
  // Clear all the nodes.  This doesnt work!
  var nodes = tree.getNodes();
  for (var x = 0; x < nodes.length; x++)
  {
    nodes[x].setChecked(false);
  }
 
  // Recheck the current node
  //node.setChecked(true);
  tree.setSelectedNode( node );
}

 

Any suggestions?

Thanks. 

  • 392
    Verified Answer
    posted

     Im answering my own question here.  I tried the other ways to make an UltraWebTree act like it has radio buttons.  None of them worked.  This does!

     

    In aspx: 

    <ignav:UltraWebTree
              ID="uwtSiteTree"
              runat="server"
              CheckBoxes="True" HiliteClass="" HoverClass="" Indentation="20" Width="436px">
                         
              <ClientSideEvents NodeChecked="TreeNodeChecked"></ClientSideEvents>
    </ignav:UltraWebTree>

     

    In BLOCKED SCRIPT 

    function TreeNodeChecked(treeName, id, bChecked)
    {
      if (!bChecked)
        return;
     
      var tree = igtree_getTreeById(treeName);
      var nodes = tree.getNodes();
      recursive_UncheckAllExcept( nodes, id );
    }

    function recursive_UncheckAllExcept( nodes, exceptId )
    {
      for (var i=0; i<nodes.length; i++)
        {
            var node = nodes[i];
            if( node.Id != exceptId )
              node.setChecked(false);
            recursive_UncheckAllExcept(node.getChildNodes(), exceptId);
        }
    }

     

    Now we just need to get it so that we can ask the control for its value and it returns the id of the selected node.  Any ideas?