How to Create Custom Using Template Binding in JavaScript Diagram?
The Syncfusion® JavaScript Diagram supports rendering custom HTML content within nodes using template binding. This allows you to create nodes with dynamic HTML elements such as buttons, forms, or other content.
To define a node with custom HTML content, set the shape
property of the node to HTML. Specify the template content using the nodeTemplate
function. Here’s how:
let diagram = new Diagram({
width: '100%',
height: '550px',
nodeTemplate: '#nodetemplate', // Referencing the template by its ID
nodes: [{
id: 'node1',
offsetX: 100,
offsetY: 100,
width: 100,
height: 100,
}],
getNodeDefaults: (obj) => {
obj.shape = { type: 'HTML' }; // Setting the shape type to HTML
obj.backgroundColor = '#6BA5D7'
return obj;
}
});
diagram.appendTo('#element');
Define the Custom HTML Template:
You can define your custom HTML content inside a <script>
tag with a unique id, which will be referenced in the nodeTemplate
property of the diagram.
<script id="nodetemplate" type="text/x-template">
<div>
<button onclick="nodeBtnClick(event)">Button</button>
</div>
</script>
Sample: Click Here
Conclusion
I hope you enjoyed learning how to create custom shapes using template binding 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!