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.

Resource menu
//<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' };
                }
            }
        }
    }
});

The processItems implementation may be an async function which awaits a result to mutate the items object.

This feature is disabled by default.

Configs

18

Common

disabledInstancePlugin
listenersEvents

Other

items: Object<String, MenuItemEntry>

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'
            }
        }
    }
},
processItems: function

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;
            }
        }
    }
},
ParameterTypeDescription
contextObject

An object with information about the menu being shown.

context.featureResourceMenu

A reference to this feature.

context.domEventEvent

The initiating event.

context.eventEvent

DEPRECATED: The initiating event.

context.pointNumber[]

The client X and Y position of the initiating event.

context.targetElementHTMLElement

The target to which the menu is being applied.

context.resourceRecordResourceModel

The record representing the current resource.

context.itemsObject<String, MenuItemEntry>

An object containing the menu item configs keyed by their id.

Returns: Boolean | null -

Returning false from this function prevents the menu being shown

clickTriggerSelectorContextMenuBase
keyMapContextMenuBase
menuContextMenuBase
namedItemsContextMenuBase
preventNativeMenuContextMenuBase
triggerEventContextMenuBase
typeContextMenuBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

19

Common

disabledInstancePlugin

Class hierarchy

isResourceMenu: Boolean= truereadonly
Identifies an object as an instance of ResourceMenu class, or subclass thereof.
isResourceMenu: Boolean= truereadonlystatic
Identifies an object as an instance of ResourceMenu class, or subclass thereof.
isContextMenuBaseContextMenuBase
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

menuContextMenuBase
menuContextContextMenuBase
preventNativeMenuContextMenuBase

Functions

29

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
showContextMenuContextMenuBase
triggerEvents
unEvents

Events

11

This 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 }) => {

});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

resourceRecordResourceModel

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 }) => {

});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

recordResourceModel

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 }) => {

});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

recordResourceModel

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 }) => {

});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

resourceRecordResourceModel

Record

checkedBoolean

Checked or not

catchAllEvents
contextMenuItemContextMenuBase
contextMenuToggleItemContextMenuBase
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

11

This 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 }) {

    }
});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

resourceRecordResourceModel

Record

This event called on the owning scheduler when an item is selected in the context menu.

new ResourceMenu({
    onResourceMenuItem({ source, menu, item, record }) {

    }
});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

recordResourceModel

Record

This event called on the owning scheduler after the context menu is shown for a resource.

new ResourceMenu({
    onResourceMenuShow({ source, menu, items, record }) {

    }
});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

recordResourceModel

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 }) {

    }
});
ParameterTypeDescription
sourceScheduler

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

resourceRecordResourceModel

Record

checkedBoolean

Checked or not

onContextMenuItemContextMenuBase
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

3
MenuContextContextMenuBase
MenuItemEntryContextMenuBase