Disable grid context menu when right clicking column header

Hello,

I wanna ask if there's a way to disable grids context menu when you are right clicking column menu ? 

Grids right click context menu should not appear when right clicking on column header.


It should only appear when clicking on grid



1 Reply

PS Pavithra Subramaniyam Syncfusion Team June 7, 2018 01:00 PM UTC

Hi Domantas, 

Thanks for contacting Syncfusion Support. 

We have checked your query and You can prevent the context menu popup for a particular area by setting ‘args.cancel’ property in the contextMenuOpen event of Essential JavaScript 2 Grid component. This event will be triggered before context menu opens. Please refer to the below code example, Documentation link and sample link. 

[component.ts] 
@Component({ 
    selector: 'app-container', 
    template: `<ejs-grid #grid id='gridcomp' [dataSource]='data' [allowSelection]='true' [allowPaging]='true' height='265px' [contextMenuItems]='contextMenuItems' 
                (contextMenuOpen)='contextMenuOpen($event)' [editSettings]='editing' [allowGrouping]='true' [allowExcelExport]='true' [allowPdfExport]='true'> 
            .    .   . 
                </ejs-grid> 
                ` 
}) 
export class AppComponent implements OnInit { 

    public data: Object[]; 
    public contextMenuItems: ContextMenuItemModel[] = ['AutoFit', 'AutoFitAll', 'SortAscending', 'SortDescending', 
                'Copy', 'Edit', 'Delete', 'Save', 'Cancel', 
                'PdfExport', 'ExcelExport', 'CsvExport', 'FirstPage', 'PrevPage', 
                'LastPage', 'NextPage', 'Group', 'Ungroup']; 
    @ViewChild('grid') 
    public grid: GridComponent; 
.   .   . 

   contextMenuOpen(e: BeforeOpenCloseMenuEventArgs){ 
     if(this.grid.getHeaderContent().contains(e.event.target)){ 
       e.cancel = true; 
       this.grid.contextMenuModule.updateItemStatus(); 
     } 
   } 


Sample               : https://plnkr.co/edit/NwK1xlIJrcXuPk1RNZ9N?p=preview  

Regards, 
Pavithra S. 


Loader.
Up arrow icon