Articles in this section
Category / Section

How to Create Hierarchical Tree with HTML Code in JS Diagram?

2 mins read

HTML content can be added in the JavaScript Diagram through an HTML type node. The shape property of the node allows you to set the type of node, and to create an HTML node, it should be set as “HTML”.

Diagram provides support to create a Hierarchical tree layout, which is used to arrange nodes automatically based on a predefined layout logic.

Create Hierarchical tree layout in diagram

  1. To generate a layout from DataSource, you have to define the business object and add the necessary data to the DataSource collection. During the layout generation, nodes and connectors can be generated automatically with the information provided through the data source, and those items will be added to NodeCollection and ConnectorCollection respectively.
  2. To arrange the nodes in a hierarchical structure, specify the layout type as HierarchicalTree.
let diagram = new Diagram({
   width: '100%',
   height: '550px',
   //Uses layout to auto-arrange nodes on the diagram page
   layout: {
       //Sets layout type
       type: 'HierarchicalTree'
   },
   //Configures data source for diagram
   nodeTemplate: '#nodetemplate',
   dataSourceSettings: {
       id: 'Id',
       parentId: 'Manager',
       dataSource: new DataManager(localBindData),
   },
});
Create the Hierarchical layout with HTML Node
  1. To create an HTML node, you should set the type of node shape to HTML.
  2. To add HTML code, define the HTML code/template in an HTML file and append the id to the nodeTemplate property.
getNodeDefaults: (obj) => {
       obj.shape = { type: 'HTML' };
       obj.width = 80;
       obj.height = 80;
       obj.backgroundColor = '#6BA5D7'
       return obj;
   }
<script id="nodetemplate" type="text/x-template">
       <div>
         <h1 class='myTitle'>${data.Role}</h1>
       </div>
</script>

Sample: Click Here

Conclusion
I hope you enjoyed learning how to create hierarchical tree with HTML code in JavaScript Diagram.

You can refer to our JavaScript Diagram feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Diagram example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied