EventMenu
Displays a context menu for events. Items are populated by other features and/or application code.
//<code-header>
fiddle.title = 'Event menu';
//</code-header>
targetElement.innerHTML = '<p>Right click an event bar to display a context menu:</p>';
const scheduler = new Scheduler({
appendTo : targetElement,
// makes scheduler as high as it needs to be to fit rows
autoHeight : true,
features : {
eventMenu : {
items : {
duplicate : {
text : 'Duplicate',
weight : 200,
icon : 'fa fa-fw fa-copy',
onItem({ item, eventRecord }) {
scheduler.eventStore.add(eventRecord.copy());
}
}
}
}
},
startDate : new Date(2018, 4, 6),
endDate : new Date(2018, 4, 13),
columns : [
{ field : 'name', text : 'Name', width : 100 }
],
resources : [
{ id : 1, name : 'Bernard' },
{ id : 2, name : 'Bianca' }
],
events : [
{ id : 1, resourceId : 1, name : 'Interview', startDate : '2018-05-07', endDate : '2018-05-10' },
{ id : 2, resourceId : 2, name : 'Meeting', startDate : '2018-05-10', endDate : '2018-05-12' },
{ id : 3, resourceId : 2, name : 'Future task', startDate : '2018-06-10', endDate : '2018-06-12' }
]
});Default event menu items
Here is the list of menu items provided by the feature and populated by the other features:
| Reference | Text | Weight | Feature | Description |
|---|---|---|---|---|
editEvent |
Edit event | 100 | EventEdit | Edit event in the event editor. Hidden when read-only |
showDetails |
Edit event | 100 | EventEdit | Show event in a non-editable form. Hidden when not read-only |
copyEvent |
Copy event | 110 | EventCopyPaste | Copy event or assignment. Hidden when read-only |
cutEvent |
Cut event | 120 | EventCopyPaste | Cut event or assignment. Hidden when read-only |
unassignEvent |
Unassign event | 300 | This feature | Unassign event. Hidden when read-only, shown for multi-assignment |
deleteEvent |
Delete event | 500 | This feature | Remove event. Hidden when read-only |
splitEvent |
Split event | 650 | Scheduler Pro only | Split an event into two segments at the mouse position |
renameSegment |
Rename segment | 660 | Scheduler Pro only | Show an inline editor to rename the segment |
eventColor ¹ |
Color | 400 | This feature | Choose background color for the event bar |
¹ Set showEventColorPickers to true to enable this item
Customizing the menu items
The menu items in the Event menu can be customized, existing items can be changed or removed,
and new items can be added. This is handled using the items config of the feature.
Add extra items for all events:
const scheduler = new Scheduler({
features : {
eventMenu : {
items : {
extraItem : {
text : 'Extra',
icon : 'fa fa-fw fa-flag',
onItem({eventRecord}) {
eventRecord.flagged = true;
}
}
}
}
}
});
Remove existing items:
const scheduler = new Scheduler({
features : {
eventMenu : {
items : {
deleteEvent : false,
unassignEvent : false
}
}
}
});
Customize existing item:
const scheduler = new Scheduler({
features : {
eventMenu : {
items : {
deleteEvent : {
text : 'Delete booking'
}
}
}
}
});
Manipulate existing items for all events or specific events:
const scheduler = new Scheduler({
features : {
eventMenu : {
// Process items before menu is shown
processItems({eventRecord, items}) {
// Push an extra item for conferences
if (eventRecord.type === 'conference') {
items.showSessionItem = {
text : 'Show sessions',
onItem({eventRecord}) {
// ...
}
};
}
// Do not show menu for secret events
if (eventRecord.type === 'secret') {
return false;
}
}
}
}
});
processItems implementation may be an async function which awaits a result to mutate the items
object.
Note that the menuContext is applied to the Menu's item event, so your onItem
handler's single event parameter also contains the following properties:
- source The Scheduler whose UI was right-clicked.
- targetElement The element right-clicked on.
- eventRecord The event record clicked on.
- resourceRecord The resource record clicked on.
- assignmentRecord The assignment record clicked on.
Video guides
Full information of the menu customization can be found in the "Customizing the Event menu, the Schedule menu, and the TimeAxisHeader menu" guide.
This feature is enabled by default
Configs
18
Configs
18Other
A function called before displaying the menu that allows manipulations of its items.
Returning false from this function prevents the menu being shown.
features : {
eventMenu : {
processItems({ items, eventRecord, assignmentRecord, resourceRecord }) {
// Add or hide existing items here as needed
items.myAction = {
text : 'Cool action',
icon : 'fa fa-fw fa-ban',
onItem : () => console.log(`Clicked ${eventRecord.name}`),
weight : 1000 // Move to end
};
if (!eventRecord.allowDelete) {
items.deleteEvent.hidden = true;
}
}
}
},
| Parameter | Type | Description |
|---|---|---|
context | Object | An object with information about the menu being shown. |
context.feature | EventMenu | A reference to this feature. |
context.domEvent | Event | The initiating event. |
context.event | Event | DEPRECATED: The initiating event. |
context.point | Number[] | The client |
context.targetElement | HTMLElement | The target to which the menu is being applied. |
context.eventRecord | EventModel | The record representing the current event. |
context.resourceRecord | ResourceModel | The record representing the current resource. |
context.assignmentRecord | AssignmentModel | The assignment record. |
context.items | Object<String, MenuItemEntry> | An object containing the menu item configs keyed by their id. |
Returning false from this function prevents the menu being shown.
Misc
Properties
20
Properties
20Common
Class hierarchy
Functions
30
Functions
30Other
Shows context menu for the provided event. If record is not rendered (outside of time span/filtered) menu won't appear.
| Parameter | Type | Description |
|---|---|---|
eventRecord | EventModel | Event record to show menu for. |
options | Object | |
options.targetElement | HTMLElement | Element to align context menu to. If provided menu will be aligned according to clientX/clientY coordinates. If omitted, context menu will be centered to event element. |
Configuration
Events
Misc
Events
10
Events
10This event fires on the owning Scheduler before the context menu is shown for an event. Allows manipulation of the items
to show in the same way as in processItems. Returning false from a listener prevents the menu from
being shown.
// Adding a listener using the "on" method
eventMenu.on('eventMenuBeforeShow', ({ source, items, eventRecord, resourceRecord, assignmentRecord, eventElement, event }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
items | Object<String, MenuItemEntry> | Menu item configs |
eventRecord | EventModel | Event record for which the menu was triggered |
resourceRecord | ResourceModel | Resource record |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement | |
event | MouseEvent | Pointer event which triggered the context menu (if any) |
This event fires on the owning Scheduler when an item is selected in the context menu.
// Adding a listener using the "on" method
eventMenu.on('eventMenuItem', ({ source, item, eventRecord, resourceRecord, assignmentRecord, eventElement }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
item | MenuItem | |
eventRecord | EventModel | |
resourceRecord | ResourceModel | |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement |
This event fires on the owning Scheduler after showing the context menu for an event
// Adding a listener using the "on" method
eventMenu.on('eventMenuShow', ({ source, menu, eventRecord, resourceRecord, assignmentRecord, eventElement }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
menu | Menu | The menu |
eventRecord | EventModel | Event record for which the menu was triggered |
resourceRecord | ResourceModel | Resource record |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement |
Event handlers
10
Event handlers
10This event called on the owning Scheduler before the context menu is shown for an event. Allows manipulation of the items
to show in the same way as in processItems. Returning false from a listener prevents the menu from
being shown.
new EventMenu({
onEventMenuBeforeShow({ source, items, eventRecord, resourceRecord, assignmentRecord, eventElement, event }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
items | Object<String, MenuItemEntry> | Menu item configs |
eventRecord | EventModel | Event record for which the menu was triggered |
resourceRecord | ResourceModel | Resource record |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement | |
event | MouseEvent | Pointer event which triggered the context menu (if any) |
This event called on the owning Scheduler when an item is selected in the context menu.
new EventMenu({
onEventMenuItem({ source, item, eventRecord, resourceRecord, assignmentRecord, eventElement }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
item | MenuItem | |
eventRecord | EventModel | |
resourceRecord | ResourceModel | |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement |
This event called on the owning Scheduler after showing the context menu for an event
new EventMenu({
onEventMenuShow({ source, menu, eventRecord, resourceRecord, assignmentRecord, eventElement }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | |
menu | Menu | The menu |
eventRecord | EventModel | Event record for which the menu was triggered |
resourceRecord | ResourceModel | Resource record |
assignmentRecord | AssignmentModel | Assignment record, if assignments are used |
eventElement | HTMLElement |
Typedefs
4
Typedefs
4A context object passed to any processItems method defined for a context menu feature, and the basis of events
fired by context menu features.
| Parameter | Type | Description |
|---|---|---|
eventRecord | EventModel | The event record clicked on. |
resourceRecord | ResourceModel | The resource record clicked on. |
assignmentRecord | AssignmentModel | The assignment record clicked on. |