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

TreeView Expand Programmatically Fails to Show any nodes

1 Answer 84 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Eric Caslake
Top achievements
Rank 1
Eric Caslake asked on 31 Dec 2009, 12:52 AM
I have a TreeView that has ExpandMode set to WebService and I would like to expand a node programmatically. I have even tried to emulate this is some client side code and I can see the web service call being made and returning data. However, the node does not expand as desired.

            String.prototype.endsWith = function(str){return (this.match(str+"$")==str)} 
 
            function nodeChecked(sender, eventArgs) { 
                var node = eventArgs.get_node(); 
                var parent = node.get_parent(); 
                var grand_parent = parent.get_parent();    
 
 
                var parent_value = parent.get_value(); 
                var parent_value_other = ""
                 
                if (parent_value.endsWith("cc")) { 
                    parent_value_other = parent_value.substring(0, parent_value.length - 2) 
 
                    var tree = $find("<%= RadTreeView1.ClientID %>"); 
                    var other_node = tree.findNodeByValue(parent_value_other); 
 
                    if (other_node.get_expanded() == false) { 
                        other_node.expand(); 
                    } 
                     
                     
                    var other_node_array = other_node.get_nodes(); 
                    for (var i = 0; i < other_node_array.get_count(); i++) { 
                        var _node = other_node_array.getNode(i); 
                        if (_node.get_text() == node.get_text()) { 
                            _node.check(); 
                            break
                        } 
                    } 
                } 
            } 


No matter what happens, the following line always shows the number of items in the list as 0.

var other_node_array = other_node.get_nodes();  

What am I doing wrong?

Thanks.

Is there something I can try to make this work client side?

1 Answer, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 05 Jan 2010, 09:05 AM
Hi Eric Caslake,

You need to move this code:

var other_node_array = other_node.get_nodes();
                    for (var i = 0; i < other_node_array.get_count(); i++) {
                        var _node = other_node_array.getNode(i);
                        if (_node.get_text() == node.get_text()) {
                            _node.check();
                            break;
                        }
                    }

to the handler of the OnClientNodePopulated event. This will ensure that the child nodes are already added.

Greetings,
Veskoni
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Eric Caslake
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or