Dynamic ref in Diagram component

Hi,

I am using react Diagram component.

On my page, am using more than one Diagram component.

Export data from component not working properly because am using the same ref for all Diagram component

ref={diagram => (diagramInstance = diagram)}
var drawData = diagramInstance.saveDiagram()

How do I use diagramInstance dynamically? 


1 Reply 1 reply marked as answer

AR Aravind Ravi Syncfusion Team September 21, 2020 08:04 AM UTC

Hi Arul, 
 
By using the dom we can able to get the diagram instance dynamically. In the dom get the diagram element through diagram’s id and after get the id get the diagram instance through ej2_instances. After get the diagram instances, you can able to access the diagram properties and diagram public methods. Please refer to the below code snippet for how to get the diagram instances at run time.  
 
//Here diagram is an id of the diagram component 
var diagram = document.getElementById('diagram').ej2_instances[0]; 
  let node = diagram.selectedItems.nodes[0]; 
diagram.exportDiagram(options); 
  diagram.dataBind(); 
 
Regards 
Aravind Ravi 
 


Marked as answer
Loader.
Up arrow icon