We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

C# MVC EJ2 Treeview, How to add custom data-attribute to nodes?

In standard html you have the ability to add additional data attributes to elements data-uid="1",

When i generate my treeview node items from code behind how can i add a custom data attribute to the specific node?

in the EJ1 version they have a option called LinkAttributes, what is the EJ2 equivalent of that option?

the reason i want these data attributes, is because i am attaching a context menu to the treeview node clicks and depending on the value of the data attribute decides what
context menu options should be displayed.

 result.Add(new TreeViewModel
                    {
                        Id = (int)parentId,
                        Name = "Areas",
                        HasChild = db.Area.Any(a => a.SiteId == parentId),
                        Expanded = false,
                        Selected = false,
                        ImageUrl = "../Images/Icons/location-active.png",
                        HtmlAttributes = "?????????"
                    });


1 Reply

SA Shameer Ali Baig Sulaiman Ali Baig Syncfusion Team February 3, 2020 12:57 PM UTC

Hi Patrick, 
 
Greetings from Syncfusion support. 
 
We have checked your reported query to how to add html attributes in TreeView node.  It is possible to add it in the TreeView component. Refer the below link for your requirement. 
 
 
In this sample, we have added Html attributes for TreeView nodes. 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Shameer Ali Baig S. 


Loader.
Live Chat Icon For mobile
Up arrow icon