Articles in this section

How to create layout with HTML nodes at runtime in React Diagram?

This article explains how to create layout with HTML nodes at runtime in React Diagram.

Using Syncfusion® React Diagram, you can create automatic layouts that visually represent the structure of an organization and its relationships. In this knowledge base article, we will explain how to dynamically create layouts with HTML nodes using the event-handling mechanisms provided by Syncfusion®. For instance, you can utilize the created event to dynamically render a layout.

To implement an automatic layout, define the layout property of the diagram and specify the desired layout type. To add an assistant to the organizational chart, use the getLayoutInfo function. Here’s a code snippet demonstrating this:

created={() => {
 // Configures data source settings
 diagramInstance.dataSourceSettings = {
   id: 'Id',
   parentId: 'Manager',
   dataSource: new DataManager(localBindData),
   doBinding: (nodeModel, data, diagram) => {
     nodeModel.shape = {
       type: 'HTML',
     };
   },
 };
}} 

To render the layout, it’s essential to assign the JSON data to the dataSource property within the dataSourceSettings object of the diagram.

created={() => {
 // Configures data source settings
 diagramInstance.dataSourceSettings = {
   id: 'Id',
   parentId: 'Manager',
   dataSource: new DataManager(localBindData),
   doBinding: (nodeModel, data, diagram) => {
     nodeModel.shape = {
       type: 'HTML',
     };
   },
 };
}} 

We have created the layout using the HTML node. When creating HTML nodes dynamically, you define a nodeTemplate that specifies the structure and appearance of each node. Here’s an example of how you might define a nodeTemplate for HTML nodes:

function diagramTemplate(data) {
   return (
     <div class="details">
       <p class="myTitle">{data.data.Role}</p>
       <p>Description</p>
       <button
         type="button"
         id={`nodeBtn_${data.data.Role}`}
         style={{ width: '100px', marginBottom: '30px' }}
       >
         {data.data.Role}
       </button>
     </div>
   );
 } 

Refer to the working sample for additional details and implementation: Sample

Conclusion

We hope you enjoyed learning how to create layouts with HTML nodes at runtime in React Diagram.

You can refer to our React Diagram feature tour page for other groundbreaking feature representations. You can explore our React Diagram documentation to understand how to present and manipulate data.

For current customers, check out our React Diagram components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our React Diagram and other React Diagram components.

Please let us know in the following comments section if you have any queries or require clarifications. You can also contact us through our support forums, BoldDesk Support, 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)
Access denied
Access denied