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

RadTreeView ScrollToNode.

3 Answers 76 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mike Beaton
Top achievements
Rank 1
Mike Beaton asked on 13 Apr 2011, 04:31 PM
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

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 18 Apr 2011, 04:23 PM
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.

0
Mike Beaton
Top achievements
Rank 1
answered on 20 Apr 2011, 09:41 AM
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

0
Peter
Telerik team
answered on 20 Apr 2011, 01:27 PM

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.

Tags
TreeView
Asked by
Mike Beaton
Top achievements
Rank 1
Answers by
Peter
Telerik team
Mike Beaton
Top achievements
Rank 1
Share this question
or