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

I want selection on the client to cascade down, preferably while allowing ctrl-clicks

2 Answers 20 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
C
Top achievements
Rank 1
C asked on 02 Mar 2015, 10:32 AM
In my tree, the leaves are the data carriers, but I want a click on a particular node to (visually) select itself and all its descending nodes. I am then using the list of selected nodes in an Ajax request.

But I haven't been able to figure out how to accomplish this.

I started out by selecting all the node's children:

var toSelect = !node.get_selected();

if (toSelect)
                node.select();
            else
                node.unselect();

 children.forEach(function(child) {
                if (toSelect )
                    child.select();                    
                else
                    child.unselect();
            });

This does indeed select all the nodes. The problem though, is that it does not show (they don't turn blue). So I was looking for a way to do this through the Telerik client side API, but failed. So I turned to Jquery:

var tree = $find("rtCustomerGroups");
var nodes = tree.get_nodes();

nodes.forEach(function(node) {
if (node.get_selected())
node.addClass("rtSelected");
else
node.removeClass("rtSelected");

The problem with this approach is that, while it works visually, the browser does not seem to like it - as it's complaining (sometimes) with a typeError saying addClass/removeClass aren't functions.

This also breaks the javascript as the next line, calling the Ajax function, never gets run.

This really bugs me, as the selection really works the way I want, including multi selection with ctrl click.

2 Answers, 1 is accepted

Sort by
0
C
Top achievements
Rank 1
answered on 02 Mar 2015, 10:33 AM
There are three duplicate posts, because I got an "error 500" after hitting submit, with no indication that the post had been submitted successfully.
0
Ivan Danchev
Telerik team
answered on 02 Mar 2015, 05:50 PM
Hello,

You can use the generated classes to apply CSS styles to the selected items, you just need a stronger selector. For instance, the following rule would make the background of the selected items blue:
html .RadTreeView .rtSelected .rtIn {
    background-color: blue;
    background-image: none;
}

Regards,
Ivan Danchev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
TreeView
Asked by
C
Top achievements
Rank 1
Answers by
C
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or