How to customize context menu items in Vue Diagram?
This article explains how to customize context menu items in Vue Diagram. The Vue Diagram feature tour provides built-in context menu items and allows you to define custom menu items through the contextMenuSettings property. The show property enables you to toggle the visibility of the context menu. The Diagram also offers default context menu items for frequently used commands.
Here is an example of enabling the context menu:
let contextMenuSettings =
{
// Enables the context menu
show: true,
},
data: function () {
return {
width: '100%',
height: '645px',
contextMenuSettings: contextMenuSettings,
};
},
To add a custom item for deleting diagram elements via the context menu and display only the custom context menu, set showCustomMenuOnly to true.
let contextMenuSettings =
{
// Enables the context menu
show: true,
items: [
{
text: 'delete',
id: 'delete',
},
],
// Hides the default context menu items
showCustomMenuOnly: true,
},
data: function () {
return {
width: '100%',
height: '645px',
contextMenuSettings: contextMenuSettings,
};
},
When a user clicks on a context menu item associated with a diagram node or connector, the “contextMenuClick” event is triggered. Define a function to perform the delete operation:
data: function () {
return {
width: '100%',
height: '645px',
contextMenuClick: (args) => {
if (args.item.id === 'delete') {
debugger;
if (
diagramInstance.selectedItems.nodes.length +
diagramInstance.selectedItems.connectors.length >
0
) {
diagramInstance.remove();
}
}
},
};
},
You can find a working example of this implementation in the provided sample on StackBlitz: Sample
Conclusion
We hope you enjoyed learning about how to delete diagram elements using the Vue Diagram context menu item.
You can refer to our Vue 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 Vue 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!