Disable Delete Event

Hi There,
I wanted to disable delete event on pressing delete button. Whenver a node is selected and user presses delete button so i do not want to node to be deleted. How can we disable it?

1 Reply

SG Shyam G Syncfusion Team August 30, 2018 05:20 AM UTC

Hi Ahman, 
 
If you need to disable delete action for an entire diagram while pressing delete key on keyboard, you can use command Manger to achieve your requirement. we have created a playground link in which we have disabled the delete action using command manager. 
 
Code example: 
$("#diagram").ejDiagram({                      
                    commandManager:{ 
                        commands: { 
                            "delete": { 
                                canExecute: function (args) { 
                                    if (args.model.selectedItems.children.length > 0) { 
                                        return true; 
                                    } 
                                }, 
                                execute: function (args) { 
                                    // do your custom actions 
                                }, 
                                gesture: { 
                                    key: ej.datavisualization.Diagram.Keys.Delete, 
                                } 
                            } 
                        } 
                    }, 
                      
                }); 
            }); 
 
 
 
Also, if you need to disable an delete action for an particular object, you can remove Delete NodeConstraints from Default NodeConstraints. Please refer to the code example below. 
 
Code example: 
var nodes = 
            [ 
                { name: "NewIdea", constraints: ej.datavisualization.Diagram.NodeConstraints.Default & ~ej.datavisualization.Diagram.NodeConstraints.Delete, width: 150, height: 60, offsetX: 300, offsetY: 60, }, 
  
            ]; 
$("#diagram").ejDiagram({        
   nodes:nodes               
}) 
 
 
Regards, 
Shyam G 


Loader.
Up arrow icon