We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Remove Connector in javascript.

Hi all,
I'am searching for a method to delete a selected connector programmatically.
I tried the following methods, but the connector will not be removed from the Diagramm:

1. Version
 var diagram = $('#DiagramContent').ejDiagram("instance");
 var  selectedItem = dialog.selectedItems[0]; // The connector was selected by the user
diagram.remove(selectedItem);
diagram.layout();

Because this doesn't work I tried the following:
var diagram = $('#DiagramContent').ejDiagram("instance");
 var  selectedItem = dialog.selectedItems[0]; // The connector was selected by the user
 var cons = $('#DiagramContent').ejDiagram("connectors");
 cons.splice($.inArray(conToDelete,cons),1);
diagram.layout();

After I am doing this Version, when I take a look in the model of the diagram, the connectors Array has lost the selected connector, but the diagram always shoes the connector between the nodes. I am using OrganizationalChart as layout type.

Hope that aybody can help me. Thanks in advanced

Andreas

3 Replies

SG Shyam G Syncfusion Team August 30, 2016 04:27 AM UTC

Hi Andreas, 

We have created a sample to achieve your requirement and it is available in the below link for download. Please refer to the code example below. 

Code example: 
    var diagram = $("#diagram").ejDiagram("instance"); 
    //to get the selected items 
    var selectedItem = diagram.model.selectedItems.children[0]; 
    if (selectedItem) { 
     //remove the selected item 
        diagram.remove(selectedItem); 
    } 
    //update the layout 
    diagram.layout(); 


Regards, 
Shyam G 



OE oserv Entwickler August 30, 2016 02:44 PM UTC

Hi Shyam,
thanks for your Reply. That was what I had done. So I have searched for another mistake I had made, and found it. I assumed, that when I remove the "Delete" constrain I only deny the deletion by using the ContextMenu or the ESC-Key. Because this should not be possible for the user, I am now Setting this flag before I call diagram.remove, an now all works as excpected.

Very Thanks

Andreas


SG Shyam G Syncfusion Team August 31, 2016 05:07 AM UTC

Hi Andreas, 

We are happy to hear that your problem is resolved. 

Regards, 
Shyam G 


Loader.
Live Chat Icon For mobile
Up arrow icon