Remvong default items from the Context Menu

Is it possible to remove default menu items (Add, Delete) from the context menu? I am adding my custom menu items using ContextMenuOpen event and I don't want default menu items rendered.



5 Replies

PE Punniyamoorthi Elangovan Syncfusion Team April 26, 2018 02:08 PM UTC

Hi Bojan, 
Thank you for contacting Syncfusion support 
We have analyzed your requirement. We can remove the default menu items from context menu by using the below code snippet. 
<script type="text/javascript"> 
        function contextMenuOpen(args) { 
              var contextMenuItems = [ 
                 { 
                     headerText: "Expand", 
                     menuId: "Expand", 
                     eventHandler: customMenuExpandCollapseHandler, 
                     iconClass: "e-expandIcon", 
                     disable: !isExpandable 
                 }, 
                 { 
                     headerText: "Collapse", 
                     menuId: "Collapse", 
                     eventHandler: customMenuExpandCollapseHandler, 
                     iconClass: "e-collapseIcon", 
                     disable: !isCollapsable 
                 } 
                ]; 
                args.contextMenuItems = []; 
                args.contextMenuItems.push.apply(args.contextMenuItems, contextMenuItems); 
} 
</script> 
 
We have prepared the sample with your requirement, please find the sample link below 
 
Please let us know if you require further assistance on this. 
Regards, 
Punniyamoorthi 
  



BK Bojan Kuhar April 27, 2018 05:26 AM UTC

Hi,

Images next to the menu items are not rendered on the same line. 

// When context menu opens we can customise menu items
    function contextMenuOpen(args) {
 
 
     var contextMenuItems = [
         {
             headerText: "Share Deals",
             menuId: "Deals",
             eventHandler: customMenuShareDeals,
             iconPath: "url(../../Content/images/Deal.png)",
         },
         {
             headerText: "Market Info",
             menuId: "Market",
             eventHandler: customMenuShareMarket,
             iconPath: "url(../../Content/images/Market.png)",
         }
     ];
     args.contextMenuItems = [];
     args.contextMenuItems.push.apply(args.contextMenuItems, contextMenuItems); 

Attachment: 20180427_72323_dddf7eb5.zip


MM Manikandan Manikam Syncfusion Team April 30, 2018 10:04 AM UTC

Hi Bojan, 
Please find the response below. 
If we assign the iconPath for custom menu item, this image will set as background image for that menu item’s icon container. Sometime this alignment issue occurs due to image size variations. 
We can resolve this alignment issue by setting  background-position as center and also we can customize the CSS style of context menu element  by overriding default style. 
Please find the code change for this below. 
[html] 
<style> 
  #custom1 > div.e-icon.e-contextmenu-image, 
  #custom2 > div.e-icon.e-contextmenu-image { 
     background-position: center; 
  } 
</style> 
We have prepared sample for this, please find the sample link below. 
Please let us know, if you require further assistance on this. 
 
Note: #custom1, #custom2 elements are menu id of custom menu item. 
 
Thanks, 
Manikandan M. 



BK Bojan Kuhar April 30, 2018 11:38 AM UTC

Applying the style that you have supplied works. 
Thank you.


JD Jayakumar Duraisamy Syncfusion Team May 1, 2018 04:01 AM UTC

Hi Bojan, 
We are glad that your issue has been resolved. Please let us know, if you need any other assistance. 
Regards, 
Jayakumar D

Loader.
Up arrow icon