Is it possible to hide the contextmenu at runtime?

Is it possible to hide the contextmenu at runtime?/change the target at runtime?

3 Replies

SD Saranya Dhayalan Syncfusion Team March 11, 2020 09:52 AM UTC

Hi Mounika 
 
Thank you for contacting Syncfusion support 
 
Query: Is it possible to hide the contextmenu at runtime?/change the target at runtime? 
 
Yes, it’s possible to hide the context menu at runtime by using close method. Also, we can change the target at runtime. We have achieved your reported scenario by changing target property in the button click event. Please find the below code snippet: 
 
@using Syncfusion.EJ2.Blazor.Navigations 
 
@using Syncfusion.EJ2.Blazor.Buttons 
 
<div class="control-section"> 
    <div class="contextmenu-control"> 
        <div id="contextmenutarget">Right click/Touch hold to open the ContextMenu</div> 
        <EjsContextMenu @ref="cmObj" Target="@target" Items="@MenuItems"></EjsContextMenu> 
    </div> 
</div> 
 
<div id="contextmenutarget1">ContextMenu</div> 
 
<EjsButton CssClass="e-flat" Content="onTargetChange" @onclick="onTargetChange"></EjsButton> 
 
<EjsButton CssClass="e-flat" Content="onClose" @onclick="onClose"></EjsButton> 
 
@code{ 
 
    public string target = "#contextmenutarget"; 
 
    EjsContextMenu cmObj; 
 
    public List<MenuItem> MenuItems = new List<MenuItem> 
{ 
    new MenuItem { Text="Cut" }, 
    new MenuItem { Text="Copy" }, 
    new MenuItem { Text ="Paste"}, 
    new MenuItem { Separator= true}, 
    new MenuItem { Text = "Link"}, 
    new MenuItem { Text = "New Comment"} 
    }; 
 
    public void onTargetChange() 
    { 
        target = "#contextmenutarget1"; // to change the target in the button click 
    } 
 
    public void onClose() 
    { 
        cmObj.Close(); // to hide the context menu 
    } 
} 
 
For your convenience we have prepared a sample. Please find the below sample link 
 
 
Could you please check the above sample and get back to us if you need further assistance on this? 
 
Regards, 
Saranya D 



MO Mounika March 11, 2020 10:05 AM UTC

Hi Saranya,
The submenu is not created next to the contextmenu position in the ui .I have followed the code in documentation.And there is js error on right click of contextmenu
Uncaught TypeError: Cannot convert undefined or null to object.
In the attached file you could see the submenu is located on topleft of the screen

Attachment: submenu_9c28dd21.7z


SD Saranya Dhayalan Syncfusion Team March 12, 2020 07:28 AM UTC

Hi Mounika, 
 
We have checked your reported issue, we suspect that this issue occurred while using beforeOpen event in the Contexmenu. Its’ a known issue and we have logged a defect report for this and the fix for this issue is estimated to be available in our Essential studio 2020 volume 1 release which is expected to be rolled out in the end of this Month. You can track the status of this defect using below link from our feedback portal,  
 
 
Regards, 
Saranya D 


Loader.
Up arrow icon