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

[Solved] Scroll selected tree node in to view

4 Answers 59 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andrew
Top achievements
Rank 1
Andrew asked on 26 Jul 2012, 02:24 PM

Hello,

Does anybody know how to scroll a selected tree node in to view?
I have a treeview in a div, under certain circumstances, this div is hidden from the user. When I set the div visible again, the selected node is not displayed.

Therefore I need to set the selected node visible again. Does anybody know how to do this?

Regards

Andrew

4 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 27 Jul 2012, 08:34 AM
Hello Andrew,

You can use the DOM scrollIntoView method, or (if you want to make the scrolling more visually appealing), the jQuery scrollTo plug-in.

Kind regards,
Alex Gyoshev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
0
Andrew
Top achievements
Rank 1
answered on 31 Jul 2012, 07:41 AM
Hi Alex,

That worked for me, thanks for your reply.

Andrew
0
Federico
Top achievements
Rank 1
answered on 19 Dec 2012, 11:37 PM
This works for me (using jQuery ScrollTo Plugin):

$("#Tree").scrollTo(".t-state-selected")


or


$("#Tree").scrollTo(".t-state-selected", 0, {offset:-50})

0
Christian
Top achievements
Rank 1
answered on 25 Apr 2013, 11:49 AM
Federico, your solution did not work for me, and I believe i know the reason.
When selecting the position of a li element inside a div, the position will always be relative to its parent, in my case, the ul element.
After severel tries, my only solution to get the scrollTo to work was this:

var diffelement = $('.k-state-focused').offset().top;
var diffdiv = $("#fileTreeContainer").offset().top; // the treeview container
var scrolledpx = parseInt($("#fileTreeContainer").scrollTop());  // how much has already been scrolled
var difference = (diffelement+scrolledpx) - diffdiv;
 
$("#fileTreeContainer").scrollTo( { top:difference+'px', left:0}, 500 );

This might not be the best soltion, but so far the only one that worked for all elements in my special case.
Tags
TreeView
Asked by
Andrew
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Andrew
Top achievements
Rank 1
Federico
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Share this question
or