ResourceMenu
Applicable only for Scheduler in vertical mode. Right click resource header cells to display a context menu.
To invoke the menu in a keyboard-accessible manner, use the SPACE key when a resource cell is focused.
//<code-header>
fiddle.title = 'Resource menu';
//</code-header>
targetElement.innerHTML = '<p>Right click a resource header cell to display the context menu</p>';
const scheduler = new Scheduler({
appendTo : targetElement,
mode : 'vertical',
// makes scheduler as high as it needs to be to fit rows
height : 600,
resourceImagePath : 'data/Scheduler/images/transparent-users/',
features : {
resourceMenu : {
items : {
// We add an extra item to the resource menu
add : {
text : 'Add resource',
icon : 'fa fa-plus',
onItem : ({ resourceRecord }) => scheduler.resourceStore.insert(scheduler.resourceStore.indexOf(resourceRecord), {
name : 'John Doe'
})
}
}
}
},
startDate : new Date(2023, 4, 8, 8),
endDate : new Date(2023, 4, 8, 20),
viewPreset : 'hourAndDay',
columns : [
{ field : 'name', text : 'Name', width : 100 }
],
resources : [
{ id : 1, name : 'Arnold Smith', image : 'arnold.png', eventColor : 'yellow' },
{ id : 2, name : 'Gloria Rogers', image : 'gloria.png', eventColor : 'blue' },
{ id : 3, name : 'Emilia Miller', eventColor : 'indigo', image : 'emilia.jpg' }
],
events : [
{ id : 1, resourceId : 1, name : 'Interview', startDate : '2023-05-08T09:00:00', endDate : '2023-05-08T11:00:00' },
{ id : 2, resourceId : 2, name : 'Meeting', startDate : '2023-05-08T15:00:00', endDate : '2023-05-08T19:00:00' },
{ id : 3, resourceId : 3, name : 'Conference', startDate : '2023-05-08T09:00:00', endDate : '2023-05-08T17:00:00' }
]
});Default menu items
The ResourceMenu feature provides only one item by default:
| Reference | Text | Weight | Description |
|---|---|---|---|
remove |
Delete | 100 | Delete the resource |
Customizing the menu items
The menu items in the resource 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 columns:
const scheduler = new Scheduler({
mode : 'vertical',
features : {
resourceMenu : {
items : {
extraItem : {
text : 'My cell item',
icon : 'fa fa-bus',
weight : 200,
onItem : () => ...
}
}
}
}
});
Remove an existing item:
const scheduler = new Scheduler({
mode : 'vertical',
features : {
resourceMenu : {
items : {
remove : null
}
}
}
});
Customize existing item:
const scheduler = new Scheduler({
mode : 'vertical',
features : {
resourceMenu : {
items : {
remove : {
text : 'Remove',
icon : 'fa fa-dumpster'
}
}
}
}
});
It is also possible to manipulate the default items and add new items in the processing function:
const scheduler = new Scheduler({
mode : 'vertical',
features : {
resourceMenu : {
processItems({items, record}) {
if (record.cost > 5000) {
items.myItem = { text : 'Split cost' };
}
}
}
}
});
processItems implementation may be an async function which awaits a result to
mutate the items object.This feature is disabled by default.
Configs
18
Configs
18Other
Menu items object containing named child menu items to apply to the feature's provided context menu.
This may add extra items as below, but you can also configure, or remove any of the default items by
configuring the name of the item as null
features : {
resourceMenu : {
// This object is applied to the Feature's predefined default items
items : {
switchToDog : {
text : 'Dog',
icon : 'fa fa-fw fa-dog',
onItem({record}) {
record.dog = true;
record.cat = false;
},
weight : 500 // Make this second from end
},
switchToCat : {
text : 'Cat',
icon : 'fa fa-fw fa-cat',
onItem({record}) {
record.dog = false;
record.cat = true;
},
weight : 510 // Make this sink to end
},
remove : {
// Change icon for the delete item
icon : 'fa fa-times'
}
}
}
},
A function called before displaying the menu that allows manipulations of its items.
Returning false from this function prevents the menu being shown.
features : {
resourceMenu : {
processItems({ items, record, column }) {
// Add or hide existing items here as needed
items.myAction = {
text : 'Cool action',
icon : 'fa fa-fw fa-ban',
onItem : () => console.log(`Clicked ${record.name}`),
weight : 1000 // Move to end
};
if (!record.allowDelete) {
items.remove.hidden = true;
}
}
}
},
| Parameter | Type | Description |
|---|---|---|
context | Object | An object with information about the menu being shown. |
context.feature | ResourceMenu | 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.resourceRecord | ResourceModel | The record representing the current resource. |
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
19
Properties
19Common
Class hierarchy
Functions
29
Functions
29Configuration
Events
Misc
Other
Events
11
Events
11This event fires on the owning scheduler before the context menu is shown for a resource. Allows manipulation of the items to show in the same way as in the processItems.
Returning false from a listener prevents the menu from being shown.
// Adding a listener using the "on" method
resourceMenu.on('resourceMenuBeforeShow', ({ source, menu, items, column, resourceRecord }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
resourceRecord | ResourceModel | Record |
This event fires on the owning scheduler when an item is selected in the context menu.
// Adding a listener using the "on" method
resourceMenu.on('resourceMenuItem', ({ source, menu, item, record }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
record | ResourceModel | Record |
This event fires on the owning scheduler after the context menu is shown for a resource.
// Adding a listener using the "on" method
resourceMenu.on('resourceMenuShow', ({ source, menu, items, record }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
record | ResourceModel | Record |
This event fires on the owning grid when a check item is toggled in the context menu.
// Adding a listener using the "on" method
resourceMenu.on('resourceMenuToggleItem', ({ source, menu, item, resourceRecord, checked }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
resourceRecord | ResourceModel | Record |
checked | Boolean | Checked or not |
Event handlers
11
Event handlers
11This event called on the owning scheduler before the context menu is shown for a resource. Allows manipulation of the items to show in the same way as in the processItems.
Returning false from a listener prevents the menu from being shown.
new ResourceMenu({
onResourceMenuBeforeShow({ source, menu, items, column, resourceRecord }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
resourceRecord | ResourceModel | Record |
This event called on the owning scheduler when an item is selected in the context menu.
new ResourceMenu({
onResourceMenuItem({ source, menu, item, record }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
record | ResourceModel | Record |
This event called on the owning scheduler after the context menu is shown for a resource.
new ResourceMenu({
onResourceMenuShow({ source, menu, items, record }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
record | ResourceModel | Record |
This event called on the owning grid when a check item is toggled in the context menu.
new ResourceMenu({
onResourceMenuToggleItem({ source, menu, item, resourceRecord, checked }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
resourceRecord | ResourceModel | Record |
checked | Boolean | Checked or not |