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

Why is it null?

2 Answers 55 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bruno
Top achievements
Rank 2
Bruno asked on 16 Sep 2009, 01:31 PM
Hi guys,

I have a tree view and I use a call to Expand only the first level so the user can see the first node expended.

IE, Safari and Chrome do not see RadTreeView only FF and Opera

What am I doing wrong here?

code:

The RadTreeView

<telerik:RadTreeView ID="RadTreeView" runat="server" OnNodeDataBound="RadTreeView_NodeDataBound"
    OnClientNodeClicked="onClientNodeClickedHandler" OnClientMouseOver="onClientMouseOverHandler"
    CheckBoxes="false" CheckChildNodes="false" MultipleSelect="true" TriStateCheckBoxes="false"
    SingleExpandPath="true" BorderColor="LightGray" BorderWidth="0">
</telerik:RadTreeView>

The call

$(document).ready(function() {
   // expand until level
   treeExpandNodes(0);
});

   function treeExpandNodes(level) {
      var treeView = $find('<%= RadTreeView.ClientID %>');
      if (treeView != null) {
         var nodes = treeView.get_allNodes();

         for (var i = 0; i < nodes.length; i++) {
            if (nodes[i].get_nodes() != null) {
               if (nodes[i].get_level() <= level)
                  nodes[i].expand();
               else
                  nodes[i].collapse();
            }
         }
      }
      else
         alert('Why is it null?'); // only in FF and Opera this alert is not called!
   }

image of the output in the 4 browsers

2 Answers, 1 is accepted

Sort by
0
Bruno
Top achievements
Rank 2
answered on 16 Sep 2009, 01:39 PM
it will work if I delay the call by 100 ms


      setTimeout(function() { treeExpandNodes(0); }, 100);

the DOM is already created, should be immediately as I could see the flick of the RadTreeView showing the first node (All Collapsed) and then the expanded until the level I wanted.




0
Veselin Vasilev
Telerik team
answered on 17 Sep 2009, 01:20 PM
Hi Bruno,

The document ready state is a little bit early in the page life cycle and the client objects are not yet initialized. That is why it works when a timeout is added.
The safest way would be to use the pageLoad or the Sys.Application.add_load() method:

function pageLoad() 
   treeExpandNodes(0); 


All the best,
Veselin Vasilev
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
Bruno
Top achievements
Rank 2
Answers by
Bruno
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or