CellMenu

Right click to display context menu for cells. To invoke the cell menu in a keyboard-accessible manner, use the SPACE key when the cell is focused.

Cell menu
//<code-header>
fiddle.title = 'Cell menu';
//</code-header>
// grid with ContextMenu feature
const grid = new Grid({
    appendTo : targetElement,

    // makes grid as high as it needs to be to fit rows
    autoHeight : true,

    features : {
        // this feature is enabled by default,
        // so no need for this unless you have changed defaults
        cellMenu : true
    },

    data : DataGenerator.generateData(5),

    columns : [
        { field : 'name', text : 'Name', flex : 1 },
        { field : 'score', text : 'Score', flex : 1 },
        {
            type    : 'action',
            actions : [
                {
                    cls : 'b-icon fa-ellipsis-h',
                    onClick({ record, target, column, grid }) {
                        grid.features.cellMenu.showMenuFor({ record, column }, { targetElement : target });
                    }
                }
            ]
        }
    ]
});

Default cell menu items

The Cell menu feature provides only one item by default:

Reference Text Weight Description
removeRow Delete 100 Delete row record

And all the other items are populated by the other features:

Reference Text Weight Feature Description
cut Cut record 110 RowCopyPaste Cut row record
copy Copy record 120 RowCopyPaste Copy row record
paste Paste record 130 RowCopyPaste Paste copied row records
search Search for value 200 Search Search for the selected cell text
pinColumn Pin column 250 PinColumns Shows a submenu to pin/unpin the column
filterMenu Filter 400 Filter Shows a submenu to control filtering. See Filter submenu.
splitGrid Split 500 Split Shows the "Split grid" sub menu
> splitHorizontally Horizontally 100 Split Split horizontally
> splitVertically Vertically 200 Split Split vertically
> splitBoth Both 300 Split Split both ways
unsplitGrid Split 400 Split Unsplit a previously split grid
>
first level of submenu

Customizing the menu items

The menu items in the Cell 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 grid = new Grid({
    features : {
        cellMenu : {
            items : {
                extraItem : {
                    text   : 'My cell item',
                    icon   : 'fa fa-bus',
                    weight : 200,
                    onItem : () => ...
                }
            }
        }
    }
});

It is also possible to add items using columns config. See examples below.

Add extra items for a single column:

const grid = new Grid({
    columns: [
        {
            field         : 'city',
            text          : 'City',
            cellMenuItems : {
                columnItem : {
                    text   : 'My unique cell item',
                    icon   : 'fa fa-beer',
                    onItem : () => ...
                }
            }
        }
    ]
});

Remove existing item:

const scheduler = new Scheduler({
    features : {
        cellMenu : {
            items : {
                removeRow : false
            }
        }
    }
});

Customize existing item:

const scheduler = new Scheduler({
    features : {
        cellMenu : {
            items : {
                removeRow : {
                    text : 'Throw away',
                    icon : 'fa fa-dumpster'
                }
            }
        }
    }
});

It is also possible to manipulate the default items and add new items in the processing function:

const grid = new Grid({
    features : {
        cellMenu : {
            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.

Full information of the menu customization can be found in the "Customizing the Cell menu and the Header menu" guide.

This feature is enabled by default.

Keyboard shortcuts

This feature has the following default keyboard shortcuts:

Keys Action Action description
Space showContextMenuByKey Shows context menu for currently focused cell
Ctrl+Space showContextMenuByKey Shows context menu for currently focused cell
Please note that Ctrl is the equivalent to Command and Alt is the equivalent to Option for Mac users

For more information on how to customize keyboard shortcuts, please see our guide.

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 : {
    cellMenu : {
        // 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
            },
            removeRow : {
                // Change icon for the delete item
                icon : 'fa fa-times'
            },
            secretItem : null
        }
    }
},
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 : {
    cellMenu : {
        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.removeRow.hidden = true;
            }
        }
    }
},
ParameterTypeDescription
contextObject

An object with information about the menu being shown.

context.featureCellMenu

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

The record representing the current row.

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

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

19

Common

disabledInstancePlugin

Class hierarchy

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

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

menuContextMenuBase
menuContextContextMenuBase
preventNativeMenuContextMenuBase

Functions

30

Other

Shows the context menu for the provided cell.

ParameterTypeDescription
cellGridLocationConfig | GridLocation

The cell descriptor to show the menu for.

optionsObject
options.targetElementHTMLElement

Element to align context menu to. If provided menu will be aligned to the center of the target element. If omitted, the context menu will be centered relative to the cell element.

LstaticLocalizable
onEvents
relayAllEvents
showContextMenuContextMenuBase
triggerEvents
unEvents

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Events

11

This event fires on the owning grid before the context menu is shown for a cell. 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
cellMenu.on('cellMenuBeforeShow', ({ source, menu, items, column, record }) => {

});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

recordModel

Record

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

// Adding a listener using the "on" method
cellMenu.on('cellMenuItem', ({ source, menu, item, column, record }) => {

});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

columnColumn

Column

recordModel

Record

This event fires on the owning grid after the context menu is shown for a cell.

// Adding a listener using the "on" method
cellMenu.on('cellMenuShow', ({ source, menu, items, column, record }) => {

});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

recordModel

Record

This event fires on the owning grid when a check item is toggled in the cell context menu.

// Adding a listener using the "on" method
cellMenu.on('cellMenuToggleItem', ({ source, menu, item, column, record, checked }) => {

});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

columnColumn

Column

recordModel

Record

checkedBoolean

Checked or not

catchAllEvents
contextMenuItemContextMenuBase
contextMenuToggleItemContextMenuBase
destroyEvents
disableInstancePlugin
enableInstancePlugin

Event handlers

11

This event called on the owning grid before the context menu is shown for a cell. 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 CellMenu({
    onCellMenuBeforeShow({ source, menu, items, column, record }) {

    }
});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

recordModel

Record

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

new CellMenu({
    onCellMenuItem({ source, menu, item, column, record }) {

    }
});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

columnColumn

Column

recordModel

Record

This event called on the owning grid after the context menu is shown for a cell.

new CellMenu({
    onCellMenuShow({ source, menu, items, column, record }) {

    }
});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemsObject<String, MenuItemEntry>

Menu item configs

columnColumn

Column

recordModel

Record

This event called on the owning grid when a check item is toggled in the cell context menu.

new CellMenu({
    onCellMenuToggleItem({ source, menu, item, column, record, checked }) {

    }
});
ParameterTypeDescription
sourceGrid

The grid

menuMenu

The menu

itemMenuItem

Selected menu item

columnColumn

Column

recordModel

Record

checkedBoolean

Checked or not

onContextMenuItemContextMenuBase
onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin

Typedefs

3
MenuContextContextMenuBase
MenuItemEntryContextMenuBase