Scroll to selected item on TreeView

1 Answer 83 Views
TreeView
Ivan
Top achievements
Rank 1
Ivan asked on 15 Sep 2024, 07:59 PM

I found an example in KendoUI for jQuery here:

 

https://docs.telerik.com/kendo-ui/knowledge-base/scroll-to-selected-item

How to do it in React TreeView?

1 Answer, 1 is accepted

Sort by
0
Vessy
Telerik team
answered on 16 Sep 2024, 05:27 PM

Hi, Ivan,

In a Kendo UI for Vue scenario you can achieve this result by updating the select variable passed to the processTreeViewItems method of the TreeView:

For convenience I prepared the following sample that could be used as a base for such implementation:

    treeDataItems() {
      return processTreeViewItems(this.tree, {
        select: this.select,
        expand: this.expand,
      });
    },
  },
  methods: {
    onItemClick(event) {
      this.select = [event.itemHierarchicalIndex];
    },
    ...
    selectRow() {
      let indexToSelect = '7';
      this.select = [indexToSelect];
    },

Regards,
Vessy
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ivan
Top achievements
Rank 1
commented on 17 Sep 2024, 05:26 PM

Thanks for the answer, but I asked about KendoReact, and the actual question would be:

If we we've got a large tree and we need to select a 55th row (on component mount  - initial render) and scroll the treeview so the user can see it. How to achieve it in KedoReact?

Vessy
Telerik team
commented on 19 Sep 2024, 11:55 AM

Hey, Ivan, 

Apologies for providing a sample for a wrong product.

The same approach can be achieved with KendoReact like demonstrated in the sample below. I also added some scrollIntoView logic to show the selected node once the selection is over, you can check it here:

Tags
TreeView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Vessy
Telerik team
Share this question
or