Change grid context menu dynamically

Hi,


How can I build my grid context menu based on specific rules? I tried using contextMenuOpening event but I have no success, infact, I got change the items of menu, but when menu is opened, just a empty panel is showed.


Can anyone help me?


3 Replies

MF Mohammed Farook J Syncfusion Team November 18, 2021 06:23 AM UTC

Hi Benjamim,

Greetings from Syncfusion support.

   Based on your requirement, you want to customize the context menu items based on a condition. Your requirement can be achieved using the `contextMenuOpen` event of the EJ2 Grid. Where you can manage showing and hiding the context menu items dynamically based on some conditions.

Kindly refer the below code example.
 
[app.component.html] 
ejs-grid [dataSource]='data' id="gridcomp" allowPaging='true' allowExcelExport='true' (contextMenuOpen)='contextMenuOpen($event)' allowPdfExport='true' allowSorting='true' 
        [contextMenuItems]="contextMenuItems" [editSettings]='editing'> 
        <e-columns> 
            <e-column field='OrderID' headerText='Order ID' width='120' textAlign='Right' isPrimaryKey='true'></e-column> 
. . .  
    </ejs-grid> 
 
[app.component.ts] 
. . .  
contextMenuOpen(args): void { 
  
        if(args.rowInfo.rowData.OrderID === 10248) { 
        args.element.ej2_instances[0].hideItems(['Copy']); 
    } else { 
        args.element.ej2_instances[0].showItems(['Copy']); 
    } 
  } 
 
In the above code example , we can hide the copy option when the row has OrderID value is 10248 while opening the context-menu. Please find the sample for your reference. 
 
 
Please get back to us for further details. 
  
Regards, 
J Mohammed Farook 



BG Benjamim Goulart Bessa November 19, 2021 06:53 PM UTC

Thank's J Mohammed Farook 


Your answer worked for me! :D







BS Balaji Sekar Syncfusion Team November 22, 2021 04:51 AM UTC

Hi Benjamim, 
  
Thanks for the update. 
  
We are happy to hear that your issue has been resolved. 
  
Please get back to us if you need further assistance. 
  
Regards, 
Balaji Sekar. 


Loader.
Up arrow icon