Creating Custom Column Menu Items

Summary

  • Bespoke Menu Items can be added to the Column Menu by developers

Developers can provide bespoke menu items in the Column Menu.

This is done using the customColumnMenu callback in Column Menu Options.

Each item is a UserColumnMenuItem with properties such as label, icon, hidden, disabled, onClick, and subMenuItems.

Deep Dive

Anatomy of a Custom Column Menu Item

Developer Guide

Providing a Standard Custom Column Menu Item

A few steps are required to define a standard Column Menu item (no frameworkComponent):

// 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

icon: {
  name: 'theme',
},
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: [
  {
    menuType: 'User',
    label: 'Hide Dashboard',
    onClick: (menuContext: ColumnMenuContext) => {
      menuContext.adaptableApi.dashboardApi.hideDashboard();
    },
  },
  {
    menuType: 'User',
    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 UserColumnMenuItem.

When the Dashboard is visible, use a Dashboard parent with Hide and Float sub items. When it is hidden (dashboardApi.isDashboardHidden()), the demo uses a single Show Dashboard item that calls showDashboard().

// Add custom menu items before default AG Grid and AdapTable blocks
columnMenuOptions: {
  customColumnMenu: (context: CustomColumnMenuContext) => {
    return [
      changeThemeMenuItem,
      dashboardMenuItem,
      '-',
      ...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 items in the desired location in the Column Menu.

Column Menu: Custom Menu Items
Fork
  • Show Dark Theme / Show Light Theme — single action at the top of the Column Menu; hidden on row-group columns; disabled for date columns
  • DashboardShow Dashboard when the Dashboard is hidden; otherwise a sub menu with Hide and Float
  • Default AG Grid and AdapTable menu items remain below