RadTreeView ScrollToNode.

4 posts, 0 answers
  1. Mike Beaton
    Mike Beaton avatar
    18 posts
    Member since:
    Sep 2009

    Posted 13 Apr 2011 Link to this post

    Hi

    I have seen this article here http://www.telerik.com/community/forums/aspnet-ajax/treeview/radtreeview-client-side-scrollintoview-for-selected-node-question.aspx where you are able to scroll the selected node to the top which is great.

    Is it also possible to scroll a node to the top from its OnClientNodeExpanded event? 

    I have tried attaching the scrollToNode code to the OnClientNodeExpanded event but it never scrolls all the way to the top. 

    Can anyone help.

    Regards

    Mike
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 18 Apr 2011 Link to this post

    Hi Mike Beaton,

    Yes, it is possible, but you need to call scrollToNode with a slight delay like this:
    <script type="text/javascript"
        function OnClientNodeExpanded(sender, args) { 
        var treeview = sender; 
        var node = treeview.findNodeByValue("this"
        setTimeout(function () { scrollToNode(treeview, node); }, 500); 
        function scrollToNode(treeview, node) { 
        var nodeElement = node.get_contentElement(); 
        var treeViewElement = treeview.get_element(); 
        var nodeOffsetTop = treeview._getTotalOffsetTop(nodeElement); 
        var treeOffsetTop = treeview._getTotalOffsetTop(treeViewElement); 
        var relativeOffsetTop = nodeOffsetTop - treeOffsetTop; 
        treeViewElement.scrollTop = relativeOffsetTop; 
    </script> 
    <telerik:RadTreeView ID="RadTreeView1" Width="200px" Height="300px" runat="server" OnClientNodeExpanded="OnClientNodeExpanded">



    Kind regards,
    Peter
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. Mike Beaton
    Mike Beaton avatar
    18 posts
    Member since:
    Sep 2009

    Posted 20 Apr 2011 Link to this post

    Thanks Peter

    That works exactly how I wanted.

    Out of curiosity is the delay to take into account the animation and the client height being re-calculated?

    Regards

    Mike

  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 20 Apr 2011 Link to this post


    Yes, your assumption is correct, Mike. Even though the name of the event suggests that the node will be already expanded when it occurs, still some extra time is needed for the height of the child group to be calculated.

    Greetings,
    Peter
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top