To hide/show a particular item of context menu which I have given on a node in diagram

Hi,
from the below code I am able to show my context menu on a node in diagram, now I want to hide my "Manage Branch Conditions" text from the context menu initially and it will be shown in some other condition only. Kindly help.

public contextMenu: ContextMenuSettingsModel = {
    show: true, items: [
      {
        text: 'Manage Landing Page', id: 'MLP',
      },
      {
        text: 'Manage Actions', id: 'MWA',
      },
      {
        text: 'Manage Participants', id: 'MP',
      },
      {
        text: 'Manage Branch Conditions', id: 'MBC'
      }

    ],
    showCustomMenuOnly: true,
  }

1 Reply

AR Aravind Ravi Syncfusion Team April 29, 2020 08:07 AM UTC

Hi Rakhi 
 
We have created a sample to hide context menu items based on some condition. When you right click on diagram before context menu open contextMenuOpen event triggers. By using contextMenuOpen event we can able to hide the context menu items. In this sample we have hide the Manage Branch Conditions text when no nodes and connectors gets selected in diagram. Please find below code snippet for how to use “contextMenuOpen” event. 
 
public contextMenuOpen(args: DiagramBeforeMenuOpenEventArgs) { 
    for (let item of args.items) { 
            if (item.text === 'Manage Branch Conditions') { 
                if (!this.diagram.selectedItems.nodes.length && !this.diagram.selectedItems.connectors.length) { 
                    args.hiddenItems.push(item.id); 
                     
                } 
            } 
        } 
   
 
We have attached a sample for you reference. Please find the sample in below link 
 
 
Regards 
Aravind Ravi 


Loader.
Up arrow icon