Category / Section
How to add icons/images beside the Scheduler context-menu items?
3 mins read
The following steps helps you to add image/icon to the Scheduler context-menu items.
- Create a Schedule sample with context-menu option by referring the following links.
Sample link: https://js.syncfusion.com/demos/web/#!/azure/schedule/contextmenu
UG link: https://help.syncfusion.com/js/schedule/context-menu
- Create the necessary style classes to be applied for the context-menu items.
<style type="text/css"> [class*="img-"] { height: 14px; left: 2px; top: 4px; width: 15px; } .img-1 { background-image: url("14.1.0.41/themes/web/content/images/schedule/print.png"); background-position: -25px 0; } .img-2 { background-image: url("14.1.0.41/themes/web/content/images/schedule/bell.png"); background-position: -25px 0; } </style>
- Add an additional field named sprite which holds the class name of the background image(s) and its properties within the contextMenuSettings property as shown below.
contextMenuSettings: { enable: true, menuItems: { appointment: [ { id: "open", text: "Open Appointment" }, { id: "delete", text: "Delete Appointment" }, { id: "customMenu3", text: "Menu Item 3" }, { id: "customMenu4", text: "Menu Item 4" }, { id: "categorize", text: "Categorize" } ], cells: [ { id: "new", text: "New Appointment", sprite: "img-1" }, { id: "recurrence", text: "New Recurring Appointment" }, { id: "today", text: "Today" }, { id: "gotodate", text: "Go to date", sprite: "img-2" }, { id: "settings", text: "Settings" }, { id: "view", text: "View", parentId: "settings" }, { id: "timemode", text: "TimeMode", parentId: "settings" }, { id: "view_Day", text: "Day", parentId: "view" }, { id: "view_Week", text: "Week", parentId: "view" }, { id: "view_Workweek", text: "Workweek", parentId: "view" }, { id: "view_Month", text: "Month", parentId: "view" }, { id: "timemode_Hour12", text: "12 Hours", parentId: "timemode" }, { id: "timemode_Hour24", text: "24 Hours", parentId: "timemode" }, { id: "businesshours", text: "Business Hours", parentId: "settings" }, { id: "customMenu1", text: "Menu Item 1" }, { id: "customMenu2", text: "Menu Item 2" } ] } }
- Before the context menu gets opened, beforeContextMenuOpen event will be raised. In that event, define the default field name of menu control, spriteCssClass additionally (default field of ejMenucontrol) which holds the sprite field name as shown below for the Scheduler context-menu items.
$(function () { var dManager = ej.DataManager(window.Default).executeLocal(ej.Query().take(10)); $("#Schedule1").ejSchedule({ width: "100%", height: "525px", currentDate: new Date(2014, 4, 5), contextMenuSettings: { enable: true, menuItems: { appointment: [ { id: "open", text: "Open Appointment" }, { id: "delete", text: "Delete Appointment" }, { id: "customMenu3", text: "Menu Item 3" }, { id: "customMenu4", text: "Menu Item 4" }, { id: "categorize", text: "Categorize" } ], cells: [ { id: "new", text: "New Appointment", sprite: "img-1" }, { id: "recurrence", text: "New Recurring Appointment" }, { id: "today", text: "Today" }, { id: "gotodate", text: "Go to date", sprite: "img-2" }, { id: "settings", text: "Settings" }, { id: "view", text: "View", parentId: "settings" }, { id: "timemode", text: "TimeMode", parentId: "settings" }, { id: "view_Day", text: "Day", parentId: "view" }, { id: "view_Week", text: "Week", parentId: "view" }, { id: "view_Workweek", text: "Workweek", parentId: "view" }, { id: "view_Month", text: "Month", parentId: "view" }, { id: "timemode_Hour12", text: "12 Hours", parentId: "timemode" }, { id: "timemode_Hour24", text: "24 Hours", parentId: "timemode" }, { id: "businesshours", text: "Business Hours", parentId: "settings" }, { id: "customMenu1", text: "Menu Item 1" }, { id: "customMenu2", text: "Menu Item 2" } ] } }, appointmentSettings: { dataSource: dManager, id: "Id", subject: "Subject", startTime: "StartTime", endTime: "EndTime", description: "Description", allDay: "AllDay", recurrence: "Recurrence", recurrenceRule: "RecurrenceRule", }, beforeContextMenuOpen: "OnBeforeOpen", }); }); function OnBeforeOpen(args) { var obj = $("#Schedule1").data("ejSchedule"); obj._contextMenu.ejMenu({ fields: { id: "id", text: "text", parentId: "parentId", spriteCssClass: "sprite" }, }); }
- Run the sample and right click the cell. Image/Icon will get added to the context-menu items as depicted in the below image,
Figure 1: Image/Icon added for context-menu items.
Sample link: https://jsplayground.syncfusion.com/tlo3u2ev