How to get parent nodes of a node on onnodeclick event in kendo ui angular?

1 Answer 529 Views
TreeView
Deepali
Top achievements
Rank 1
Deepali asked on 26 May 2021, 06:27 PM
hey team

 

I am facing another issue, that when a user clicks on a node in kendo treeview, onnodeclick event gets triggered. In its event handler, how can we get the parent nodes of that node?

 




 

1 Answer, 1 is accepted

Sort by
0
Yanmario
Telerik team
answered on 28 May 2021, 02:26 PM

Hi Deepali,

When the TreeView is bound to flat data, each data item has its parent id, and this id can retrieve the parent. The item itself is available in the nodeClick handler event data as e.item.dataItem:

https://stackblitz.com/edit/treeview-flat-data-node-click-parent?file=app/app.component.ts

On the other hand, when the TreeView is bound to heterogeneous data, the data items don't have a notion about their parents (only their children). In such scenarios you will need to implement some custom logic to retrieve the parent item based on its hierachical index. The clicked item index is available in the nodeClick event data as e.item.index, the parent index will be the clicked item's index without the last "_xx". Here is a custom JavaScript sample implementation of the described approach:

https://stackblitz.com/edit/treeview-heterogeneous-node-click-parent-information?file=app/app.component.ts

I hope this helps.

Regards,
Yanmario Menev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeView
Asked by
Deepali
Top achievements
Rank 1
Answers by
Yanmario
Telerik team
Share this question
or