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

How to set color for nodes in ORG CHART

7 Answers 646 Views
OrgChart
This is a migrated thread and some comments may be shown as answers.
Duy
Top achievements
Rank 1
Duy asked on 20 Apr 2016, 10:30 AM

Hi guys!

I have a problem. I create a family tree, and i use ORG CHART. And now, i need to show nodes by gender, the man with green and the woman with pink. And I bind data to ORG CHART form SQL/SERVER. I hope my problem will resolve. Thanks :))))))

 

 

7 Answers, 1 is accepted

Sort by
0
Duy
Top achievements
Rank 1
answered on 20 Apr 2016, 03:59 PM
Please, help me
0
Duy
Top achievements
Rank 1
answered on 21 Apr 2016, 07:15 AM
Can anyone help me,please! :'(
0
Ivan Danchev
Telerik team
answered on 22 Apr 2016, 12:25 PM
Hello Duy,

In order to achieve that you should have a column in the database (for example "Gender"), which will hold the value "male" or "female" for each record. You can then access that value in the OrgChart's NodeDataBound event and use it to set a CSS class to the node:
protected void RadOrgChart1_NodeDataBound(object sender, OrgChartNodeDataBoundEventArguments e)
{
    DataRowView dataSourceRow = (DataRowView)e.Node.DataItem;
 
    if (dataSourceRow.Row["Gender"].ToString() == "male")
    {
        e.Node.CssClass = "nodeMale";
    }
    else
    {
        e.Node.CssClass = "nodeFemale";
    }
}
Since the event fires for each node, every node will have one of the these two classes set after the event finishes executing. You can then add two CSS rules, applying different background color to the corresponding elements.

Here are the two CSS rules, which set the background color of the nodes with classes "nodeMale" and "nodeFemale":
.nodeFemale .rocItem .rocItemContent {
    background-color: pink;
}
 
.nodeMale .rocItem .rocItemContent {
    background-color: green;
}


Regards,
Ivan Danchev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Teja
Top achievements
Rank 1
Veteran
answered on 23 Jul 2020, 04:21 PM
May i know how to achieve changing node color at client side ?
0
Peter Milchev
Telerik team
answered on 28 Jul 2020, 08:58 AM

Hello Teja,

You can use the client-side API of the OrgChart to access the nodes:

Then, with the client-side API of the OrgChartNode, you can access the node's DOM element and style it as required, either via direct styling or by adding a CSS class to it.

Regards,
Peter Milchev
Progress Telerik

0
Teja
Top achievements
Rank 1
Veteran
answered on 28 Jul 2020, 05:42 PM

Thank you Peter for the reply.

I had gone through client side API's before and implemented the code but however i couldn't highlight the node which i am interested in. Let say, i have implemented client side search for finding the node by name on the node, i was able to find the node by name scroll into the view but however i couldn't highlight the node with some color / style. Please help me with some sample code.

0
Peter Milchev
Telerik team
answered on 31 Jul 2020, 08:07 AM

Hello Teja,

You can use JavaScript to apply styles to the HTML elements:

Also, you can find child elements inside the node that also need styling:

Another option is to set a CSS class to the element and use regular CSS for styling:

To get a better understanding on the HTML structure of the node, you can follow the suggestions in the first two points of the Improve Your Debugging Skills with Chrome DevTools blog post explaining how to inspect the generated HTML and check the applied styles for various elements. 

Once you know the styles you need to override, you can use the same style selector and add "html body " in front of it to make it more specific, "stronger". More on CSS specificity you can find here: 

 

Regards,
Peter Milchev
Progress Telerik

Tags
OrgChart
Asked by
Duy
Top achievements
Rank 1
Answers by
Duy
Top achievements
Rank 1
Ivan Danchev
Telerik team
Teja
Top achievements
Rank 1
Veteran
Peter Milchev
Telerik team
Share this question
or