TaskMenu

Displays a context menu for tasks. Items are populated by other features and/or application code. Configure it with false to disable it completely. If enabled, CellMenu feature is not available. Cell context menu items are handled by this feature.

Default task menu items

Here is the list of menu items provided by the Task menu feature and populated by the other features:

Reference Text Weight Feature Description
editTask Edit task 100 TaskEdit Edit the task. Hidden when read-only
showDetails Show details 100 TaskEdit Show details of the task in a non-editable form. Hidden when not read-only
cut Cut task 110 TaskCopyPaste Cut the task
copy Copy task 120 TaskCopyPaste Copy the task
paste Paste task 130 TaskCopyPaste Paste the task
search* Search for value 200 Search Search for cell text
filterMenu Filter 400 Filter Shows a submenu to control filtering. See Filter submenu.
add Add... 500 This feature Submenu for adding tasks
>addTaskAbove Task above 510 This feature Add a new task above the selected task
>addTaskBelow Task below 520 This feature Add a new task below the selected task
>milestone Milestone 530 This feature Add a new milestone below the selected task
>subtask Subtask 540 This feature Add a new task as a child of the current, turning it into a parent
>successor Successor 550 This feature Add a new task below current task, linked using an "Finish-to-Start" dependency
>predecessor Predecessor 560 This feature Add a new task above current task, linked using an "Finish-to-Start" dependency
convertToMilestone Convert to milestone 600 This feature Turns the selected task into a milestone. Shown for leaf tasks only
splitTask Split task 650 EventSegments Split the task
indent Indent 700 This feature Add the task as a child of its previous sibling, turning that task into a parent
outdent Outdent 800 This feature Turn the task into a sibling of its parent
deleteTask Delete task 900 This feature Remove the selected task
linkTasks Add dependencies 1000 This feature Add dependencies between two or more selected tasks
unlinkTasks Remove dependencies 1010 This feature Removes dependencies between selected tasks
taskColor ¹ Color 1100 This feature Choose background color for the task bar

¹ Set showTaskColorPickers to true to enable this item

*
items that are shown for the locked grid cells only
>
first level of submenu

Customizing the menu items

The menu items in the Task 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.

To add extra items for all events:

const gantt = new Gantt({
    features : {
        taskMenu : {
            // Extra items for all events
            items : {
                flagTask : {
                    text : 'Extra',
                    icon : 'fa fa-fw fa-flag',
                    onItem({taskRecord}) {
                        taskRecord.flagged = true;
                    }
                }
            }
        }
    }
});

Remove menu/submenu items

Items can be removed from the menu:

const gantt = new Gantt({
    features : {
        taskMenu : {
            items : {
                // Hide delete task option
                deleteTask: false,

                // Hide item from the `add` submenu
                add: {
                    menu: {
                         subtask: false
                    }
                }
            }
        }
    }
});

Manipulate items for specific tasks

Items can behave different depending on the type of the task:

const gantt = new Gantt({
    features : {
        taskMenu : {
            // Process items before menu is shown
            processItems({ items, taskRecord }) {
                 // Push an extra item for conferences
                 if (taskRecord.type === 'conference') {
                     items.showSessions = {
                         text : 'Show sessions',
                         ontItem({taskRecord}) {
                             // ...
                         }
                     };
                 }

                 // Do not show menu for secret events
                 if (taskRecord.type === 'secret') {
                     return false;
                 }
            }
        }
    }
});

Full information of the menu customization can be found in the "Customizing the Task menu" guide.

This feature is enabled by default

Task menu
//<code-header>
fiddle.title = 'Task menu';
//</code-header>
targetElement.innerHTML = '<p>A basic grid with no extra configuration, this what you get straight out of the box</p>';

const gantt = new Gantt({
    appendTo : targetElement,

    // makes the Gantt chart as tall as it needs to be to fit all rows
    autoHeight : true,

    columns : [
        { type : 'name', field : 'name', text : 'Name' }
    ],

    features : {
        taskMenu : true
    },

    startDate : new Date(2019, 1, 4),
    endDate   : new Date(2019, 1, 11),

    tasks : [
        {
            id        : 1,
            name      : 'Project A',
            startDate : '2019-02-04',
            duration  : 5,
            expanded  : true,
            children  : [
                {
                    id        : 11,
                    name      : 'Preparation work',
                    startDate : '2019-02-04',
                    duration  : 5
                }
            ]
        }
    ]
});

Configs

18

Common

disabledInstancePlugin
listenersEvents

Other

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         : {
   taskMenu : {
        processItems({ items, taskRecord }) {
            // 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;
            }
        }
    }
},
ParameterTypeDescription
contextObject

An object with information about the menu being shown.

context.featureContextMenuBase

A reference to the menu feature which owns this context.

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.taskRecordTaskModel

The record representing the current task.

context.columnColumn

The current column.

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
itemsContextMenuBase
keyMapContextMenuBase
menuContextMenuBase
namedItemsContextMenuBase
preventNativeMenuContextMenuBase
triggerEventContextMenuBase
typeContextMenuBase

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

21

Common

disabledInstancePlugin

Class hierarchy

isTaskMenu: Boolean= truereadonly
Identifies an object as an instance of TaskMenu class, or subclass thereof.
isTaskMenu: Boolean= truereadonlystatic
Identifies an object as an instance of TaskMenu class, or subclass thereof.
isContextMenuBaseContextMenuBase
isEventMenuEventMenu
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable
isTimeSpanMenuBaseTimeSpanMenuBase

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

menuContextMenuBase
menuContextEventMenu
preventNativeMenuContextMenuBase

Functions

30

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

LstaticLocalizable
onEvents
relayAllEvents
showContextMenuContextMenuBase
triggerEvents
unEvents

Events

13

This event fires on the owning Gantt before the context menu is shown for a task. 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
taskMenu.on('taskMenuBeforeShow', ({ source, items, taskRecord, taskElement }) => {

});
ParameterTypeDescription
sourceGantt
itemsMenuItemEntry[]

Menu item configs

taskRecordTaskModel

Event record for which the menu was triggered

taskElementHTMLElement

This event fires on the owning Gantt when an item is selected in the context menu.

// Adding a listener using the "on" method
taskMenu.on('taskMenuItem', ({ source, item, taskRecord, taskElement }) => {

});
ParameterTypeDescription
sourceGantt
itemMenuItem
taskRecordTaskModel
taskElementHTMLElement

This event fires on the owning Gantt after showing the context menu for an event

// Adding a listener using the "on" method
taskMenu.on('taskMenuShow', ({ source, menu, taskRecord, taskElement }) => {

});
ParameterTypeDescription
sourceGantt
menuMenu

The menu

taskRecordTaskModel

Event record for which the menu was triggered

taskElementHTMLElement
catchAllEvents
contextMenuItemContextMenuBase
contextMenuToggleItemContextMenuBase
destroyEvents
disableInstancePlugin
enableInstancePlugin
eventMenuItemEventMenu
eventMenuShowEventMenu

Event handlers

13

This event called on the owning Gantt before the context menu is shown for a task. 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 TaskMenu({
    onTaskMenuBeforeShow({ source, items, taskRecord, taskElement }) {

    }
});
ParameterTypeDescription
sourceGantt
itemsMenuItemEntry[]

Menu item configs

taskRecordTaskModel

Event record for which the menu was triggered

taskElementHTMLElement

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

new TaskMenu({
    onTaskMenuItem({ source, item, taskRecord, taskElement }) {

    }
});
ParameterTypeDescription
sourceGantt
itemMenuItem
taskRecordTaskModel
taskElementHTMLElement

This event called on the owning Gantt after showing the context menu for an event

new TaskMenu({
    onTaskMenuShow({ source, menu, taskRecord, taskElement }) {

    }
});
ParameterTypeDescription
sourceGantt
menuMenu

The menu

taskRecordTaskModel

Event record for which the menu was triggered

taskElementHTMLElement
onContextMenuItemContextMenuBase
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

4
MenuContextContextMenuBase
MenuItemEntryContextMenuBase