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

Adding an ID to a tree element

3 Answers 46 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ewgenij
Top achievements
Rank 1
Veteran
Ewgenij asked on 12 Oct 2020, 03:38 PM
Is it possible? I want to add an ID attribute to each tree element, <id=1> for example. Of course, the ID should be different for each element How can I do that?

3 Answers, 1 is accepted

Sort by
0
Svet
Telerik team
answered on 14 Oct 2020, 03:08 PM

Hi Ewgenij,

The nodeTemplate directive can be used for the purpose. It exposes an index property which is unique for each node item. The index can be added to the each node in the templated in the following way:

 

     <kendo-treeview
         [nodes]="data"
         kendoTreeViewExpandable

         kendoTreeViewHierarchyBinding
         childrenField="items">
       <ng-template kendoTreeViewNodeTemplate let-dataItem let-index="index">
         <span [id]="index"> {{ dataItem.text }}</span>
       </ng-template>
     </kendo-treeview>

I hope this helps. Also, please expect a representative from our sales team to contact you regarding your license.

Regards,
Svetlin
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/.

0
Ewgenij
Top achievements
Rank 1
Veteran
answered on 15 Oct 2020, 07:05 AM
Hello, that would not meet my requirements for an index. The index is an hierarchical index according to your documentation. For example, it would be 0_0. So, when I change the hierarchy level of a particular element, the index would also change, for example to 0_1. So I would not be able to localize the same element again. Is there any possibility to provide a stable index? For example based on my custom element data?
0
Accepted
Svet
Telerik team
answered on 19 Oct 2020, 06:10 AM

Hi Ewgenij,

Indeed, there isn't such built-in feature that would allow to achieve the requirement. Instead what could be done is to use some custom recursive logic in order to iterate the items. That approach will allow to create and store the stable indexes in an item property as per the use - case scenario.

Regards,
Svetlin
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
Ewgenij
Top achievements
Rank 1
Veteran
Answers by
Svet
Telerik team
Ewgenij
Top achievements
Rank 1
Veteran
Share this question
or