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

Add class to checkboxes on top level

3 Answers 242 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
-DJ-
Top achievements
Rank 1
-DJ- asked on 19 Apr 2012, 04:01 PM
Hi, how would you go about adding a css class to any top level checkboxes?

Regards,
-DJ-

3 Answers, 1 is accepted

Sort by
0
Bozhidar
Telerik team
answered on 23 Apr 2012, 08:36 AM
Hi Daniel,

The checkbox element already has a class "rtChk", and you can use the following css selector to filter only the top level checkboxes:
.RadTreeView>ul>li>div>.rtChk
{ }

Or if you want to add your own, this could be done in the OnClientLoad event with the following script:
function clientLoad(sender) {
    var nodes = sender.get_nodes();
    for (var i = 0; i < nodes.get_count(); i++) {
        $telerik.$(nodes.getNode(i).get_checkBoxElement()).addClass("customClassName");
    }
}

 
Regards,
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
-DJ-
Top achievements
Rank 1
answered on 24 Apr 2012, 11:12 AM
Hi Bozhidar,

Thank you for your help.

What I was doing before accessing top level nodes (and trying to access the checkboxes) was in codebehind. 
Now, with your solution I would prefer to add a class to the top level nodes from the javascript as well.

However, something like $telerik.$(nodes.getNode(i)).addClass("rtLevel1"); has no effect.

On top of that, I would prefer only to add these classes to nodes (and their respective checkboxes) if the node in question has children. 

Javascript really isn't my strong suit as you can probably tell.

Regards,
-DJ-
0
Bozhidar
Telerik team
answered on 26 Apr 2012, 08:01 AM
Hello Daniel,

In order to assign a class to the node itself, you have to get a reference to it's DOM element, which is done with the get_element() function. And to determine whether a node has children or not, you can check the number of its child nodes.

Here is the modified clientLoad() function:
function clientLoad(sender) {
    var nodes = sender.get_nodes();
    for (var i = 0; i < nodes.get_count(); i++) {
        var node = nodes.getNode(i);
 
        if (node.get_nodes().get_count() > 0) {
            $telerik.$(node.get_checkBoxElement()).addClass("customClassName");
            $telerik.$(node.get_element()).addClass("customClassName");
        }
    }
}

 
Regards,
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.
Tags
TreeView
Asked by
-DJ-
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
-DJ-
Top achievements
Rank 1
Share this question
or