This question is locked. New answers and comments are not allowed.
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
0
Accepted
Hello Andrew,
Alex Gyoshev
the Telerik team
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
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):
or
$("#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:
This might not be the best soltion, but so far the only one that worked for all elements in my special case.
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 containervar scrolledpx = parseInt($("#fileTreeContainer").scrollTop()); // how much has already been scrolledvar 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.