How to Update the Node Data at Runtime in React Diagram Layout?
The React Diagram allows you to dynamically update the node data layout (such as annotations or labels) at runtime. In this guide, we will demonstrate how to update the content of a selected node programmatically.
To modify the content of a node dynamically, you can use the content property of the node’s shape.
Below is a code example that shows how to update the node data at runtime when node Data button is clicked.
const nodeData = function () {
// Check if any node is selected
if (diagramInstance.selectedItems.nodes.length > 0) {
// Dynamically update the node content
(diagramInstance.selectedItems.nodes[0].shape ).content = 'Head of the board';
diagramInstance.dataBind();
}
};
Check for Selected Node: We use diagram.selectedItems.nodes.length to check if any node is selected in the diagram.
Update Node Content: If a node is selected, we modify the content property of the node’s shape. In this example, the content is set to ‘Head of the board’.
Sample:
Refer to the working sample for additional details and implementation: StackBlitz
Conclusion
We hope you enjoyed learning how to update the node data at runtime in React Diagram layout.
You can refer to our React Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our React 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, BoldDesk Support, or feedback portal. We are always happy to assist you!