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.
//<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' };
}
}
}
}
});
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 |
Ctrl is the equivalent to Command and Alt
is the equivalent to Option for Mac usersFor more information on how to customize keyboard shortcuts, please see our guide.
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 : {
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
}
}
},
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;
}
}
}
},
| Parameter | Type | Description |
|---|---|---|
context | Object | An object with information about the menu being shown. |
context.feature | CellMenu | 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.record | Model | The record representing the current row. |
context.column | Column | The current column. |
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
30
Functions
30Other
Shows the context menu for the provided cell.
| Parameter | Type | Description |
|---|---|---|
cell | GridLocationConfig | GridLocation | The cell descriptor to show the menu for. |
options | Object | |
options.targetElement | HTMLElement | 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. |
Configuration
Events
Misc
Events
11
Events
11This 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
record | Model | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
column | Column | Column |
record | Model | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
record | Model | 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
column | Column | Column |
record | Model | Record |
checked | Boolean | Checked or not |
Event handlers
11
Event handlers
11This 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
record | Model | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
column | Column | Column |
record | Model | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
items | Object<String, MenuItemEntry> | Menu item configs |
column | Column | Column |
record | Model | 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 }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
column | Column | Column |
record | Model | Record |
checked | Boolean | Checked or not |