ColumnHeaderMenu
Adds a menu button (···) to column headers, clicking it displays a menu. Items are populated by other features
and/or application code.
//<code-header>
fiddle.title = 'Column header menu';
//</code-header>
const taskBoard = new TaskBoard({
appendTo : targetElement,
features : {
columnDrag : true,
columnToolbars : false,
// Enable column header menus
columnHeaderMenu : true
},
// Columns to display
columns : [
'todo',
'doing',
'done'
],
// Field used to pair a task to a column
columnField : 'status',
// Project using inline data
project : {
tasks : [
{ id : 1, name : 'Click ··· above', status : 'todo' }
]
}
});Default items
These are the default items provided by TaskBoard features:
| Reference | Weight | Feature | Description |
|---|---|---|---|
addTask |
100 | This feature | Add a new task to this column |
moveColumnLeft |
200 | ColumnDrag | Move column one step left |
moveColumnRight |
300 | ColumnDrag | Move column one step right |
lock |
400 | ColumnLock | Lock columns on right side |
unlock |
400 | ColumnLock | Unlock locked columns |
Default items in the menu can be changed or removed and new items can be added. This is handled using the items config of the feature.
Add items
Add menu items for all column headers by adding a key (used as menu item ref) with a config object for a menu item as the value to the items config:
const taskBoard = new TaskBoard({
features : {
columnHeaderMenu : {
items : {
flagTasks : {
text : 'Flag task',
icon : 'fa-fw fa-flag',
onItem({ columnRecord }) {
columnRecord.tasks.forEach(taskRecord => taskRecord.flagged = true);
}
}
}
}
}
});
//<code-header>
fiddle.title = 'Column header menu add';
//</code-header>
const taskBoard = new TaskBoard({
appendTo : targetElement,
features : {
columnToolbars : false,
// Enable column header menus
columnHeaderMenu : {
items : {
// Add a new custom menu item
flagTask : {
text : 'Flag tasks',
icon : 'fa-fw fa-flag b-color-red',
weight : 50, // At top
onItem({ columnRecord }) {
columnRecord.tasks.forEach(taskRecord => taskRecord.flagged = true);
}
}
}
}
},
// Columns to display
columns : [
'todo',
'doing',
'done'
],
// Field used to pair a task to a column
columnField : 'status',
// Project using inline data
project : {
taskStore : {
fields : ['flagged']
},
tasks : [
{ id : 1, name : 'Task 1', status : 'todo' },
{ id : 2, name : 'Task 2', status : 'doing', flagged : true },
{ id : 3, name : 'Task 3', status : 'done' },
{ id : 4, name : 'Task 4', status : 'done' }
]
},
// Custom renderer to add an icon to a cards header when flagged
taskRenderer({ taskRecord, cardConfig }) {
cardConfig.children.header.children.flag = taskRecord.flagged && {
tag : 'i',
class : 'fa fa-flag b-color-red'
};
}
});Remove items
To remove default items, configure them as null in the items config:
const taskBoard = new TaskBoard({
features : {
columnHeaderMenu : {
items : {
moveColumnLeft : null,
moveColumnRight : null
}
}
}
});
//<code-header>
fiddle.title = 'Column header menu remove';
//</code-header>
const taskBoard = new TaskBoard({
appendTo : targetElement,
features : {
columnDrag : true,
columnToolbars : false,
// Enable column header menus
columnHeaderMenu : {
items : {
// Remove these default items
moveColumnLeft : null,
moveColumnRight : null
}
}
},
// Columns to display
columns : [
'todo',
'doing',
'done'
],
// Field used to pair a task to a column
columnField : 'status',
// Project using inline data
project : {
tasks : [
{ id : 1, name : 'Click ··· above', status : 'todo' }
]
}
});Customize items
To customize default items, supply a new config object for them in the items config. It will merge with the default config object:
const taskBoard = new TaskBoard({
features : {
columnHeaderMenu : {
items : {
// Change the text of the "Add new task" item
addTask : {
text : 'New card'
}
}
}
}
});
//<code-header>
fiddle.title = 'Column header menu customize';
//</code-header>
const taskBoard = new TaskBoard({
appendTo : targetElement,
features : {
columnToolbars : false,
// Enable column header menus
columnHeaderMenu : {
items : {
addTask : { text : 'New card' }
}
}
},
// Columns to display
columns : [
'todo',
'doing',
'done'
],
// Field used to pair a task to a column
columnField : 'status',
// Project using inline data
project : {
tasks : [
{ id : 1, name : 'Task 1', status : 'todo' },
{ id : 2, name : 'Task 2', status : 'doing' },
{ id : 3, name : 'Task 3', status : 'done' }
]
}
});Manipulating items at runtime
Manipulate items for all columns or specific columns at runtime by supplying a processItems function:
const taskBoard = new TaskBoard({
features : {
columnHeaderMenu : {
// Process items before menu is shown
processItems({ columnRecord, items }) {
// Push an extra item for the done column
if (columnRecord.id === 'done') {
items.archive = {
text : 'Archive',
icon : 'fa-fw fa-archive',
onItem({ columnRecord }) {
columnRecord.tasks.forEach(taskRecord => taskRecord.archived = true);
}
};
}
// Do not show "Add new task" for the todo column
if (columnRecord.id === 'todo') {
items.addTask = null;
}
}
}
}
});
processItems implementation my be an async function which awaits a result to
mutate the items object.//<code-header>
fiddle.title = 'Column header menu process items';
//</code-header>
const taskBoard = new TaskBoard({
appendTo : targetElement,
features : {
columnDrag : true,
columnToolbars : false,
columnHeaderMenu : {
// Process items before menu is shown
processItems({ columnRecord, items }) {
// Push an extra item for the done column
if (columnRecord.id === 'done') {
items.archive = {
text : 'Archive',
icon : 'fa-fw fa-archive',
onItem({ columnRecord }) {
columnRecord.tasks.forEach(taskRecord => taskRecord.archived = true);
}
};
}
// Do not show "Add new task" for the todo column
if (columnRecord.id === 'todo') {
items.addTask = null;
}
}
}
},
// Columns to display
columns : [
'todo',
'doing',
'done'
],
// Field used to pair a task to a column
columnField : 'status',
// Project using inline data
project : {
tasks : [
{ id : 1, name : 'Task 1', status : 'todo' },
{ id : 2, name : 'Task 2', status : 'doing' },
{ id : 3, name : 'Task 3', status : 'done' }
]
}
});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 column header |
Ctrl+Space |
showContextMenuByKey | Shows context menu for currently focused column header |
For more information on how to customize keyboard shortcuts, please see our guide.
Configs
11
Configs
11Other
This is a preconfigured set of items used to create the default context menu.
The items provided by this feature are listed in the intro section of this class. You can configure
existing items by passing a configuration object to the keyed items.
To remove existing items, set corresponding keys null:
const scheduler = new Scheduler({
features : {
columnHeaderMenu : {
items : {
addTask : null
}
}
}
});
See the class description for more examples.
A function called before displaying the menu that allows manipulations of its items.
Returning false from this function prevents the menu from being shown.
const taskBoard = new TaskBoard({
features : {
columnHeaderMenu : {
processItems({ columnRecord, items }) {
// Push an extra item for the todo column
if (columnRecord.id === 'todo') {
items.finishAll = {
text : 'Finish all',
icon : 'fa-fw fa-check'
onItem({ columnRecord }) {
columnRecord.tasks.forEach(taskRecord => taskRecord.status = 'done');
}
};
}
}
}
}
});
| Parameter | Type | Description |
|---|---|---|
context | Object | An object with information about the menu being shown |
context.feature | ColumnHeaderMenu | 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.columnRecord | ColumnModel | The column for which the menu will be shown |
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
16
Properties
16Common
Class hierarchy
Other
Functions
28
Functions
28Configuration
Events
Misc
Other
Events
9
Events
9This event fires on the owning TaskBoard when an item is selected in the column header menu.
// Adding a listener using the "on" method
columnHeaderMenu.on('cellMenuItem', ({ source, menu, item, columnRecord }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
columnRecord | ColumnModel | The column |
This event fires on the owning TaskBoard after the context menu is shown for a column header.
// Adding a listener using the "on" method
columnHeaderMenu.on('cellMenuShow', ({ source, menu, items, columnRecord }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
items | Object<string, MenuItemEntry> | Menu item configs |
columnRecord | ColumnModel | The column |
This event fires on the owning TaskBoard when a check item is toggled in the column header menu.
// Adding a listener using the "on" method
columnHeaderMenu.on('cellMenuToggleItem', ({ source, menu, item, columnRecord, checked }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
columnRecord | ColumnModel | The column |
checked | Boolean | Checked or not |
This event fires on the owning TaskBoard before the menu is shown for a column header. 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
columnHeaderMenu.on('columnHeaderMenuBeforeShow', ({ source, menu, items, columnRecord }) => {
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
items | Object<string, MenuItemEntry> | Menu item configs |
columnRecord | ColumnModel | The column |
Event handlers
9
Event handlers
9This event called on the owning TaskBoard when an item is selected in the column header menu.
new ColumnHeaderMenu({
onCellMenuItem({ source, menu, item, columnRecord }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
columnRecord | ColumnModel | The column |
This event called on the owning TaskBoard after the context menu is shown for a column header.
new ColumnHeaderMenu({
onCellMenuShow({ source, menu, items, columnRecord }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
items | Object<string, MenuItemEntry> | Menu item configs |
columnRecord | ColumnModel | The column |
This event called on the owning TaskBoard when a check item is toggled in the column header menu.
new ColumnHeaderMenu({
onCellMenuToggleItem({ source, menu, item, columnRecord, checked }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
item | MenuItem | Selected menu item |
columnRecord | ColumnModel | The column |
checked | Boolean | Checked or not |
This event called on the owning TaskBoard before the menu is shown for a column header. 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 ColumnHeaderMenu({
onColumnHeaderMenuBeforeShow({ source, menu, items, columnRecord }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | TaskBoard | The grid |
menu | Menu | The menu |
items | Object<string, MenuItemEntry> | Menu item configs |
columnRecord | ColumnModel | The column |