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 Item
  • icon - an Icon to display
  • disabled - whether Menu Item is disabled
  • hidden - whether Menu Item is visible
  • onClick - what happens when the Menu Item is clicked
  • subMenuItems - lower levels of Menu Items (enables the Menu Item to be as deeply nested as required)
Column Menu: Custom Menu Items
Fork
  • 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 Date Columns

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';
}
1
Provide a Label and Menu Type

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();
},
2
Supply an onClick function

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',
3
Specify whether Menu Item should be Hidden or Disabled

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',
},

4
Provide an Icon

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();
  },
},
],
5
Add Sub Menu Items (if required)

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,
    ];
  },
},
6
Add the custom Menu Item to Column Menu

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.