I notice that there's a "get" for a node's main CSS class but I can't seem to find a "set". Is there a built-in way to manipulate this? I've done the following for the moment.
function setNodeCssClass(node, cssClass){ var currentClass = node.get_cssClass(); if (currentClass != cssClass) { //This method sets an internal object value but it doesn't affect the //actual HTML element. node._set_value($IG.DataTreeNodeProps.CssClass, cssClass); //We need to manipulate the anchor element's CSS class. var anchor = node.get_anchorElement(); if (currentClass != "") { //Replace the current class. var regex = new RegExp("(^|\s)" + currentClass + "(?!\S)", "g"); anchor.className = anchor.className.replace(regex, cssClass); } else { //Just add the new one. anchor.className += " " + cssClass; } }}
Hello Vector,
Thank you for contacting Infragistics!
I have some follow up questions:
What are the styles you want to set?Are these styles going to change or are they something you only want to set once when the app/site starts?Are all the nodes going to have the same styles or are different nodes going to have different styles?
Hi Mike,
I currently want to set the main CSS class, the same as the DataTreeNode.CssClass property on the server-side.
This tree is dynamically built node by node and I set the server-side CSS initially for each one, but there are times after rendering when I have to change it client-side for a particular few. (This scenario doesn't use postbacks.)
Each node could have different style, yes.
Okay, thanks for looking into it.
Thank you for the update. After doing some further looking into there isn’t a specific set method for the css styles on the client in JavaScript. If on the server when setting up the nodes you want to set CSS you can see the CssClass, ActiveCssClass, DisabledCssClass, HoverCssClass, SelectedCssClass:
https://ko.infragistics.com/help/aspnet/16.2/infragistics.web~infragistics.web.ui.navigationcontrols.datatreenode~cssclass
If you have to apply CSS in JavaScript what you currently have is currently the best way.