Disable right click on existing event

Hi, I am following this example to create context menu for my scheduler -https://ej2.syncfusion.com/angular/demos/#/material/schedule/context-menu.
How can I disable right clicking on an existing event? if I hide all the items for that scenario, I am seeing an empty context menu upon right clicking, which I don't want. Context menu should only show up on right clicking on empty cells, not existing events. Right clicking on existing events should simply be ignored.

3 Replies

VD Vinitha Devi Murugan Syncfusion Team December 18, 2019 10:42 AM UTC

Hi Jose, 
 
Syncfusion Greetings. 
 
We achieved your requirement by making use of beforeOpen event of context menu and same can be available in below link. 
 

 onContextMenuBeforeOpen(args: BeforeOpenCloseMenuEventArgs): void { 
        let newEventElement: HTMLElement = document.querySelector('.e-new-event') as HTMLElement; 
        if (newEventElement) { 
            remove(newEventElement); 
            removeClass([document.querySelector('.e-selected-cell')], 'e-selected-cell'); 
        } 
        let targetElement: HTMLElement = <HTMLElement>args.event.target; 
        if (closest(targetElement, '.e-contextmenu')) { 
            return; 
        } 
        this.selectedTarget = closest(targetElement, '.e-appointment,.e-work-cells,' + 
            '.e-vertical-view .e-date-header-wrap .e-all-day-cells,.e-vertical-view .e-date-header-wrap .e-header-cells'); 
        if (isNullOrUndefined(this.selectedTarget)) { 
            args.cancel = true; 
            return; 
        } 
        if (this.selectedTarget.classList.contains('e-appointment')) { 
         args.cancel = true; 
            return; 
        } 
        this.menuObj.hideItems(['Save', 'Delete', 'EditRecurrenceEvent', 'DeleteRecurrenceEvent'], true); 
        this.menuObj.showItems(['Add', 'AddRecurrence', 'Today'], true); 
    } 

Kindly try the above solution and let us know, if you need further assistance on this.  

Regards, 
M.Vinitha devi 



JL jose lara December 20, 2019 04:05 AM UTC

thx. this works as expected


VD Vinitha Devi Murugan Syncfusion Team December 20, 2019 06:40 AM UTC

Hi Jose, 
 
Thanks for your update. 
 
We are happy to hear that our solution has fulfilled your requirement.  
 
Regards, 
M.Vinitha devi 


Loader.
Up arrow icon