Column Menu - Custom Items
Summary
- Bespoke Menu Items can be added to the Column Menu by developers
Developers can provide bespoke Menu Items to add to the Column Menu.
Like all Column Menu manipulation, it is done using the customColumnMenu property in Column Menu Options.
A number of properties can be provided for a bespoke Menu Item, including:
label- the text that appears in the Menu Itemicon- an Icon to displaydisabled- whether Menu Item is disabledhidden- whether Menu Item is visibleonClick- what happens when the Menu Item is clickedsubMenuItems- lower levels of Menu Items (enables the Menu Item to be as deeply nested as required)
- This example showws how to add a Custom Column Menu Item (to change the Theme)
- We place the item at the top of the Column Menu - and leave the default AG Grid and AdapTable Menu Items in place
- The custom Column Menu Item is hidden when opening the Column Menu in a Row-Grouped Column and disabled for
DateColumns
Expand to see the Menu Options configuration
Deep Dive
Anatomy of a Custom Column Menu Item
Developer Guide
Providing a Custom Column Menu Item
A few steps are required to define a Column Menu item:
// Provide Menu Type of 'User'
// Set the Label to Expand or Collapse based on current state
menuType: 'User',
label: (menuContext: ColumnMenuContext) => {
return menuContext.adaptableApi.dashboardApi.isDashboardCollapsed()
? 'Expand Dashboard'
: 'Collapse Dashboard';
}The menuType is always 'User'.
The label property provides the Custom Menu Item's text.
It returns either a string directly or a function which receives ColumnMenuContext and returns a string
// Expand or Collapse the Dashboard as required
onClick: (menuContext: ColumnMenuContext) => {
menuContext.adaptableApi.dashboardApi.isDashboardCollapsed()
? menuContext.adaptableApi.dashboardApi.expandDashboard()
: menuContext.adaptableApi.dashboardApi.collapseDashboard();
},The onClick function is invoked by AdapTable when the menu item is selected by the user.
It receives a ColumnMenuContext object and returns void.
// Make the Menu item hidden for Row Group Columns
hidden: menuContext.isRowGroupColumn,
// Make the Menu Item disabled for Date Columns
disabled: menuContext.adaptableColumn?.dataType == 'Date',Use hidden and disabled properties to set visibility and if enabled
Note
- In earlier versions of AdapTable, these 2 properties were functions that could be set dynamically each time the menu opened
- However this same logic can now be more flexibly set when configuring the Column Menu
// Provide an Icon
icon: {
src: 'https://img.icons8.com/flat-round/344/traffic-light--v1.png',
},
The Icon can be an object, URL or HTML Element
Find Out More
See Guide to Adaptable Icons for full details on the different types of Icons that can be used
// Provide 2 sub menu items to hide and float the Dashboard
subMenuItems: [
{
label: 'Hide Dashboard',
onClick: (menuContext: ColumnMenuContext) => {
menuContext.adaptableApi.dashboardApi.hideDashboard();
},
},
{
label: 'Float Dashboard',
onClick: (menuContext: ColumnMenuContext) => {
menuContext.adaptableApi.dashboardApi.floatDashboard();
},
},
],Each Menu Item can have Sub Menu Items allowing you to provide nested Menus as deep as required.
Each Sub Menu Item is simply another Menu Item object.
// Add custom menu Item before AG Grid and AdapTable menu items
columnMenuOptions: {
customColumnMenu: (context: CustomColumnMenuContext) => {
return [
customDashboardMenuItem,
'-',
...context.defaultAgGridMenuStructure,
'-',
...context.defaultAdaptableMenuStructure,
];
},
},The customColumnMenu property receives all AG Grid and AdapTable menu items as context, both a full list and the default structure.
Place the custom menu item in the desired location in the Context Menu.