New to Kendo UI for jQueryStart a free 30-day trial

Scroll to the Selected TreeView Item

Environment

ProductProgress® Kendo UI® TreeView for jQuery
Operating SystemWindows 10 64bit
Visual Studio VersionVisual Studio 2017
Preferred LanguageJavaScript

Description

How can I scroll the viewport to the selected node of the Kendo UI for jQuery TreeView?

Solution

The following example demonstrates how to achieve the desired scenario.

    <div id="tree"></div>

    <script>
      // Set up: generate the data, select an item.
      var data = [];
      for (var i = 0; i < 1000; i++) {
        data.push({ text: "Item " + i });
      }
      $("#tree").kendoTreeView({
        dataSource: data
      });
      var treeview = $("#tree").data("kendoTreeView");
      treeview.select(treeview.findByText("Item 500"));

      // Scroll to the selected item.
      var itemScrollTop = treeview.select()[0].offsetTop;
      $("html,body").animate({ scrollTop: itemScrollTop });
    </script>

See Also