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
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"
;
}
}
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
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
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.
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:
- https://api.jquery.com/find/
- https://api.jquery.com/closest/
- https://api.jquery.com/category/traversing/tree-traversal/
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