Adding an ID to a tree element

4 posts, 1 answers
  1. Ewgenij
    Ewgenij avatar
    11 posts
    Member since:
    Jun 2020

    Posted 12 Oct Link to this post

    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?
  2. Svetlin
    Admin
    Svetlin avatar
    444 posts

    Posted 14 Oct Link to this post

    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/.

  3. Ewgenij
    Ewgenij avatar
    11 posts
    Member since:
    Jun 2020

    Posted 15 Oct in reply to Svetlin Link to this post

    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?
  4. Answer
    Svetlin
    Admin
    Svetlin avatar
    444 posts

    Posted 19 Oct Link to this post

    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/.

Back to Top