This is a migrated thread and some comments may be shown as answers.

How to findControl() in Current Node Only

2 Answers 82 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Marbry
Top achievements
Rank 1
Marbry asked on 16 Nov 2011, 08:23 PM
Hello, I apprently mistakenly thought that the client function findControl() would only search the node that I call it on, but it's not.

It's searching all children nodes of it as well.

var comboBox  = node.findControl( "ComboBoxID" );

comboBox should be null for some nodes that it isn't.  It's traversing the tree structure and finding a match several levels down.

How would I limit that to just within the current node and not within any child nodes?

2 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 17 Nov 2011, 04:42 PM
Hi Marbry,

You must override the findControl method. Here's what it should look like:

Telerik.Web.UI.RadTreeNode.prototype.findControl = function (id) {
   var parent = $telerik.$(this.get_element())
                 .find(".rtIn:first")
                 .children(".rtTemplate")
                 .get(0);
   if (parent) {
      var children = parent.getElementsByTagName("*");
         for (var i = 0, l = children.length; i < l; i++) {
            var childID = children[i].id;
            if (childID && childID.endsWith(id))
               return $find(childID);
            }
         }
         return null;
      }



All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Marbry
Top achievements
Rank 1
answered on 22 Nov 2011, 06:09 PM
That worked well. I had the same issue with the findElement() call doing something similar with a check box.

This check in the client context menu click handler got around the problem though.

var element = node.get_element();
                    if ( element != null )
                    {
                        var checkBox = $telerik.findElement( element, "Property_CB" );
                        if ( checkBox != null && ( checkBox.parentNode.parentNode.parentNode.parentElement.uniqueID == node._element.uniqueID ) )
{}


Thanks.
Tags
TreeView
Asked by
Marbry
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Marbry
Top achievements
Rank 1
Share this question
or