Articles in this section
Category / Section

How to Trigger Event When Diagram is Read-Only in JavaScript Diagram?

2 mins read

In Syncfusion® JavaScript Diagram, you can make the diagram read-only while still triggering events like click by disabling the select constraints on nodes and connectors, along with the zoom constraint on the diagram. This effectively prevents interactions such as selection and zooming. The getNodeDefaults method uses NodeConstraints to disable the selection functionality on nodes, while the getConnectorDefaults method uses ConnectorConstraints to disable the selection functionality on connectors. Additionally, the DiagramConstraints disable the zoom functionality in diagram.

The following code snippet demonstrates how to configure these settings and trigger the click event.

//Disable the Select constraint for nodes
 getNodeDefaults: function (obj) {
   obj.width = 100;
   obj.height = 100;
   obj.constraints =
     ej.diagrams.NodeConstraints.Default & ~ej.diagrams.NodeConstraints.Select;
   return obj;
 },
 //Disable the Select constraint for connectors
 getConnectorDefaults: function (connector) {
 connector.constraints =
     ej.diagrams.ConnectorConstraints.Default &
     ~ej.diagrams.ConnectorConstraints.Select;
   return { style: { strokeColor: '#024249', strokeWidth: 2 } };
 },

//Disable the Zoom constraint for diagram
var diagram = new ej.diagrams.Diagram({
 width: '100%',
 height: '645px',
 nodes: nodes,
 connectors: connections,
 constraints:
   ej.diagrams.DiagramConstraints.Default &
   ~ej.diagrams.DiagramConstraints.Zoom,
 click: function () {
   alert('Click Event is triggered');
 },
}); 

Sample : Click here for sample

Conclusion
I hope you enjoyed learning how to trigger click event when diagram is in read-only mode 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