# Creating Custom Column Menu Items

Canonical page: https://www.adaptabletools.com/docs/ui-column-menu-custom-items

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

## Topics on this Page

| Approach                                           | When to use                                                                                                                                              |
| -------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Standard custom item](#standard-custom-menu-item) | `menuType: 'User'` with `label`, `onClick`, optional `subMenuItems` — combine inside `customColumnMenu`                                                  |
| [Framework menu row](#react-custom-menu-component) | `frameworkComponent` / `render` for richer UI — see also [Building Custom Components](https://www.adaptabletools.com/docs/ui-tutorial-building-custom-components/index.md) |

You still return the full menu array from **`customColumnMenu`** in [Column Menu Options](https://www.adaptabletools.com/docs/technical-reference-column-menu/index.md) (reorder AdapTable / AG Grid items **and** append User items). Configure layout first on [Configuring the Column Menu](https://www.adaptabletools.com/docs/ui-column-menu-configuring/index.md).

Developers can provide **bespoke** menu items in the Column Menu.

This is done using the `customColumnMenu` callback in [Column Menu Options](https://www.adaptabletools.com/docs/technical-reference-column-menu/index.md).

Each item is a [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md) with properties such as `label`, `icon`, `hidden`, `disabled`, `onClick`, and `subMenuItems`.

### Anatomy of a Custom Column Menu Item

The key object is [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md):

| Property | Type | Description |
| --- | --- | --- |
| [disabled](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#disabled) | `boolean` | Whether menu item is disabled |
| [frameworkComponent](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#frameworkcomponent) | [`MenuItemFrameworkComponent`](https://www.adaptabletools.com/docs/reference/menuitemframeworkcomponent.md)`<`[`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)`>` | Optional Framework Component (React, Angular or Vue) used to render the<br/>content of this menu item.<br/><br/>When supplied, AG Grid renders the component inside the menu row using<br/>its own framework adapter. The component receives AG Grid&#39;s<br/>`CustomMenuItemProps`, with the AdapTable-specific extras<br/>(`adaptableApi`, `menuContext`, plus anything passed via<br/>`menuItemParams`) available as `props.menuItemParams`.<br/><br/>Supported in the React, Vue and Angular variants of AdapTable.<br/><br/>For Vue, supply a factory that returns the Vue Component (NOT a render<br/>call), e.g. `({ adaptableApi }) => MyMenuItem`. AG Grid Vue then<br/>instantiates the component using its own framework adapter and passes<br/>`name`, `icon`, `menuItemParams`, ... as props.<br/><br/>For Angular, supply `{ type: MyMenuItemComponent }` where the component<br/>implements `IMenuItemAngularComp` (with `agInit(params)` to receive<br/>`params.menuItemParams.adaptableApi` and `params.menuItemParams.menuContext`).<br/>The `onSetup` callback on `AngularFrameworkComponent` is NOT honoured<br/>for menu items because AG Grid owns the component lifecycle. |
| [hidden](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#hidden) | `boolean` | Whether menu item is hidden |
| [icon](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#icon) | [`AdaptableIcon`](https://www.adaptabletools.com/docs/reference/adaptableicon.md) | Optional icon to display |
| [label](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#label) | `string` | Text to appear in the Menu Item |
| [menuItemParams](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#menuitemparams) | `Record<string, unknown>` | Extra parameters passed through to the Framework Component (alongside<br/>`adaptableApi` and `menuContext`). |
| [menuType](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#menutype) | `'User'` | Type of Menu - always &#39;User&#39; |
| [onClick](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#onclick) | `(menuContext: `[`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)`) => void` | Function invoked when the Menu Item is clicked |
| [subMenuItems](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md#submenuitems) | [`CustomColumnMenuItem`](https://www.adaptabletools.com/docs/reference/customcolumnmenuitem.md)`[]` | Array of Menu Items, enabling limitless levels of menus |

The `onClick` handler receives [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md):

| Property | Type | Description |
| --- | --- | --- |
| [adaptableColumn](https://www.adaptabletools.com/docs/reference/columnmenucontext.md#adaptablecolumn) | [`AdaptableColumn`](https://www.adaptabletools.com/docs/reference/adaptablecolumn.md)`<TData>` | Current AdapTable Column |
| [agGridColumn](https://www.adaptabletools.com/docs/reference/columnmenucontext.md#aggridcolumn) | `Column` | Current AG Grid Column |
| [isRowGroupColumn](https://www.adaptabletools.com/docs/reference/columnmenucontext.md#isrowgroupcolumn) | `boolean` | Whether current Column is Row Group |
| [adaptableContext](https://www.adaptabletools.com/docs/reference/columnmenucontext.md#adaptablecontext) | `any` | Custom application Context provided in `AdaptableOptions.adaptableContext` |

<!-- framework: vanilla -->
### Vanilla

### Providing a Standard Custom Column Menu Item

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

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

```ts {3,4}
// 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 `onClick` function is invoked by AdapTable when the menu item is selected by the user.

It receives a `ColumnMenuContext` object and returns void.

```ts {2}
// Expand or Collapse the Dashboard as required
onClick: (menuContext: ColumnMenuContext) => {
  menuContext.adaptableApi.dashboardApi.isDashboardCollapsed()
    ? menuContext.adaptableApi.dashboardApi.expandDashboard()
    : menuContext.adaptableApi.dashboardApi.collapseDashboard();
},
```

Use `hidden` and `disabled` properties to set visibility and if enabled

```ts {2,4}
// 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',
```

The Icon can be an object, URL or HTML Element

```ts {2}
icon: {
  name: 'theme',
},
```

See [Guide to Adaptable Icons](https://www.adaptabletools.com/docs/ui-tutorial-creating-icon/index.md) for full details on the different types of Icons that can be used

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`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md).

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()`.

```ts {2}
// 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();
    },
  },
],
```

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.

```ts {5}
// Add custom menu items before default AG Grid and AdapTable blocks
columnMenuOptions: {
  customColumnMenu: (context: CustomColumnMenuContext) => {
    return [
      changeThemeMenuItem,
      dashboardMenuItem,
      '-',
      ...context.defaultAgGridMenuStructure,
      '-',
      ...context.defaultAdaptableMenuStructure,
    ];
  },
},
```

**Example: Column Menu: Custom Menu Items**

Adding Custom Menu Items to Column Menus

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

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomColumnMenuContext,
  UserColumnMenuItem,
} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Column Menu Items',
  columnMenuOptions: {
    customColumnMenu: (context: CustomColumnMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserColumnMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() == 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {
          name: 'theme',
        },
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType == 'date',
        onClick: () =>
          adaptableApi.themeApi.getCurrentTheme() == 'light'
            ? adaptableApi.themeApi.loadDarkTheme()
            : adaptableApi.themeApi.loadLightTheme(),
      };

      const dashboardMenuItem: UserColumnMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAgGridMenuStructure,
        '-',
        ...defaultAdaptableMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['SystemStatus'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Grouped Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'open_issues_count',
            'week_issue_change',
            'updated_at',
            'license',
            'created_at',
            'has_wiki',
            'pushed_at',
            'open_issues_count',
            'description',
          ],
          Name: 'Grouped Layout',
          RowGroupValues: {
            RowGroupDefaultBehavior: 'collapsed',
            GroupKeys: [
              {
                RowGroupedColumns: ['language'],
                ExceptionGroupKeys: [['JavaScript']],
              },
            ],
          },
          RowGroupedColumns: ['language'],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

<!-- /framework -->

<!-- framework: react,angular,vue -->
### React / Angular / Vue

There are two ways to add bespoke Column Menu items:

1. **Standard menu item** — a [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md) with `label`, `onClick`, and related properties
2. **Framework menu component** — `frameworkComponent` when you need custom UI inside the menu item

## Standard Custom Menu Item

This options is suitable for most use cases and no `frameworkComponent` is required.

### Providing a Standard Custom Column Menu Item

Most custom entries use a standard [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md).

AdapTable renders the Menu Item for you.

The `menuType` is always `'User'`.

The `label` is the menu text—a string, or a function that receives [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md) and returns a string.

```ts {1,2}
menuType: 'User',
label: (menuContext: ColumnMenuContext) => {
  return menuContext.adaptableApi.themeApi.getCurrentTheme() === 'light'
    ? 'Show Dark Theme'
    : 'Show Light Theme';
},
```

`onClick` runs when the user selects the item. It receives [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md).

```ts {1}
onClick: (menuContext: ColumnMenuContext) => {
  const {themeApi} = menuContext.adaptableApi;
  themeApi.getCurrentTheme() === 'light'
    ? themeApi.loadDarkTheme()
    : themeApi.loadLightTheme();
},
```

Use `hidden` and `disabled` on the [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md).

```ts {1,2}
hidden: context.isRowGroupColumn,
disabled: context.adaptableColumn?.dataType === 'date',
```

The icon can be an object, URL, or HTML element.

```ts {2}
icon: {
  name: 'theme',
},
```

See [Guide to Adaptable Icons](https://www.adaptabletools.com/docs/ui-tutorial-creating-icon/index.md) for full details on Icons

Use `subMenuItems` for nested menus. Each entry is another [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md).

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

```ts {1}
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();
    },
  },
],
```

The `customColumnMenu` callback receives default menu structures on `context`. Build items such as `changeThemeMenuItem` and `dashboardMenuItem`, then place them where you want in the Column Menu (often before the default blocks).

```ts {5}
columnMenuOptions: {
  customColumnMenu: (context: CustomColumnMenuContext) => {
    return [
      changeThemeMenuItem,
      dashboardMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
      '-',
      ...context.defaultAgGridMenuStructure,
    ];
  },
},
```

<!-- /framework -->

<!-- framework: react -->
### React

**Example: Column Menu: Standard Custom Items**

Standard custom Column Menu items (React)

- This example contains 2 standard Custom Column Menu Items:
  - **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
  - **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (React); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts  [template]
  agGridModules.ts     [template]
  App.tsx
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.tsx            [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#react).

**`src/App.tsx`**

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
  CustomColumnMenuContext,
  UserColumnMenuItem,
} from '@adaptabletools/adaptable-react-aggrid';

import {GridOptions} from 'ag-grid-enterprise';

import '@adaptabletools/adaptable-react-aggrid/index.css';
import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';

const App: React.FunctionComponent = () => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const [adaptOptions] = useState<AdaptableOptions<WebFramework>>({
    primaryKey: 'id',
    adaptableId: 'Standard Column Menu Items Demo',
    stateOptions: {loadState: () => Promise.resolve({})},
    columnMenuOptions: {
      customColumnMenu: (context: CustomColumnMenuContext) => {
        const {
          defaultAgGridMenuStructure,
          defaultAdaptableMenuStructure,
          isRowGroupColumn,
          adaptableColumn,
          adaptableApi,
        } = context;

        const changeThemeMenuItem: UserColumnMenuItem = {
          menuType: 'User',
          label:
            adaptableApi.themeApi.getCurrentTheme() === 'light'
              ? 'Show Dark Theme'
              : 'Show Light Theme',
          icon: {name: 'theme'},
          hidden: isRowGroupColumn,
          disabled: adaptableColumn?.dataType === 'date',
          onClick: () => {
            const {themeApi} = adaptableApi;
            themeApi.getCurrentTheme() === 'light'
              ? themeApi.loadDarkTheme()
              : themeApi.loadLightTheme();
          },
        };

        const dashboardMenuItem: UserColumnMenuItem =
          adaptableApi.dashboardApi.isDashboardHidden()
            ? {
                menuType: 'User',
                label: 'Show Dashboard',
                onClick: () => adaptableApi.dashboardApi.showDashboard(),
              }
            : {
                menuType: 'User',
                label: 'Dashboard',
                subMenuItems: [
                  {
                    menuType: 'User',
                    label: 'Hide Dashboard',
                    onClick: menuContext =>
                      menuContext.adaptableApi.dashboardApi.hideDashboard(),
                  },
                  {
                    menuType: 'User',
                    label: 'Float Dashboard',
                    onClick: menuContext =>
                      menuContext.adaptableApi.dashboardApi.floatDashboard(),
                  },
                ],
              };

        return [
          changeThemeMenuItem,
          dashboardMenuItem,
          '-',
          ...defaultAdaptableMenuStructure,
          '-',
          ...defaultAgGridMenuStructure,
        ];
      },
    },
    initialState: {
      Dashboard: {
        Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
      },
      Theme: {CurrentTheme: 'dark'},
      Layout: {
        CurrentLayout: 'Standard Layout',
        Layouts: [
          {
            Name: 'Standard Layout',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'license',
              'created_at',
              'has_wiki',
              'updated_at',
              'pushed_at',
              'description',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  });
  const [agGridOptions] = useState<GridOptions>(gridOptions);

  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
    </div>
  );
};

export default App;
```

## React Custom Menu Component

Use `frameworkComponent` on [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want a custom layout, extra controls, or live state in the shortcut area.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

- AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/react-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration
- Use `props.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md) and [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)

### Providing a Custom React Column Menu Item

This component receives AG Grid props plus `menuItemParams` populated by AdapTable with `adaptableApi` and the active `menuContext`.

Call `useGridMenuItem({ configureDefaults: () => true })` to opt into AG Grid's default menu behaviour.

```tsx
import {useGridMenuItem} from 'ag-grid-react';
import {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-react-aggrid';

type MenuItemProps = {
  name: string;
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: ColumnMenuContext | ContextMenuContext;
  };
};

export const ThemeToggleMenuItem = (props: MenuItemProps) => {
  useGridMenuItem({configureDefaults: () => true});

  const {adaptableApi} = props.menuItemParams;
  const isDark = adaptableApi.themeApi.getCurrentTheme() === 'dark';

  return (
    <div>
      <span
        className="ag-menu-option-part ag-menu-option-icon"
        role="presentation"
      />
      <span className="ag-menu-option-part ag-menu-option-text">
        {props.name}
      </span>
      <span className="ag-menu-option-part ag-menu-option-shortcut">
        Currently: {isDark ? 'Dark' : 'Light'}
      </span>
      <span className="ag-menu-option-part ag-menu-option-popup-pointer" />
    </div>
  );
};
```

In `customColumnMenu`, return a `UserColumnMenuItem` and assign your React component to `frameworkComponent`.

```ts {6}
columnMenuOptions: {
  customColumnMenu: (context: CustomColumnMenuContext) => {
    const themeMenuItem: UserColumnMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: ThemeToggleMenuItem,
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
      '-',
      ...context.defaultAgGridMenuStructure,
    ];
  },
},
```

`adaptableApi` and `menuContext` are on `props.menuItemParams`.

```ts
const {adaptableApi, menuContext} = props.menuItemParams;
const columnId = menuContext.adaptableColumn?.columnId;
```

### Anatomy of a React Column Menu Item Component

AG Grid passes `name`, `icon`, `disabled`, `subMenu`, `shortcut`, and `checked` to your component.

AdapTable adds on `props.menuItemParams`:

- `adaptableApi` - the [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` - [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md) or [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)

Use `useGridMenuItem({ configureDefaults: () => true })` for default click, keyboard, and dismiss behaviour.

Wrap the four `ag-menu-option-part` spans in a single root element (for example a `<div>`).

Do not use a React Fragment: AG Grid treats only the first child of the React container as the menu item, so a fragment leaves the label and shortcut unstyled and invisible.

**Example: React Custom Column Menu Item**

Providing a React Component as a Custom Column Menu Item

- Theme-toggle menu item at the top of every Column Menu

Demo project (React); the files without a marker are shown below:

```text
src/
  agGridModules.ts         [template]
  App.tsx
  columnDefs.ts            [template]
  gridOptions.ts           [template]
  index.tsx                [template]
  onAdaptableReady.ts      [template]
  rowData.ts               [template]
  styles.css               [template]
  ThemeToggleMenuItem.tsx
package.json               [template]
tsconfig.json              [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#react).

**`src/App.tsx`**

```ts
import * as React from 'react';
import {useState} from 'react';
import {
  Adaptable,
  AdaptableApi,
  AdaptableOptions,
  AdaptableReadyInfo,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-react-aggrid';

import {GridOptions} from 'ag-grid-enterprise';

// import adaptable css
import '@adaptabletools/adaptable-react-aggrid/index.css';
import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {ThemeToggleMenuItem} from './ThemeToggleMenuItem';
import {WebFramework} from './rowData';

const App: React.FunctionComponent = () => {
  const adaptableApiRef = React.useRef<AdaptableApi>(null);

  const [adaptOptions] = useState<AdaptableOptions<WebFramework>>({
    primaryKey: 'id',
    adaptableId: 'Custom Menu Item Demo',
    stateOptions: {loadState: () => Promise.resolve({})},
    columnMenuOptions: {
      customColumnMenu: (context: CustomColumnMenuContext) => {
        const themeMenuItem: UserColumnMenuItem = {
          menuType: 'User',
          label: 'Toggle Theme',
          frameworkComponent: ThemeToggleMenuItem,
          onClick: () => {
            const themeApi = context.adaptableApi.themeApi;
            themeApi.getCurrentTheme() === 'dark'
              ? themeApi.loadLightTheme()
              : themeApi.loadDarkTheme();
          },
        };
        return [
          themeMenuItem,
          '-',
          ...context.defaultAdaptableMenuStructure,
          '-',
          ...context.defaultAgGridMenuStructure,
        ];
      },
    },
    initialState: {
      Theme: {CurrentTheme: 'dark'},
      Layout: {
        CurrentLayout: 'Standard Layout',
        Layouts: [
          {
            Name: 'Standard Layout',
            TableColumns: [
              'name',
              'language',
              'github_stars',
              'license',
              'created_at',
              'has_wiki',
              'updated_at',
              'pushed_at',
              'description',
            ],
            AutoSizeColumns: true,
          },
        ],
      },
    },
  });
  const [agGridOptions] = useState<GridOptions>(gridOptions);

  return (
    <div style={{display: 'flex', flexFlow: 'column', height: '100vh'}}>
      <div id="demoOutputAbove"></div>
      <Adaptable.Provider
        gridOptions={agGridOptions}
        adaptableOptions={adaptOptions}
        modules={[...agGridModules]}
        onAdaptableReady={(adaptableReadyInfo: AdaptableReadyInfo) => {
          adaptableApiRef.current = adaptableReadyInfo.adaptableApi;
          onAdaptableReady(adaptableReadyInfo);
        }}>
        <Adaptable.UI style={{flex: 'none'}} />
        <Adaptable.AgGridReact />
      </Adaptable.Provider>
      <div id="demoOutputBelow"></div>
    </div>
  );
};
export default App;
```

**`src/ThemeToggleMenuItem.tsx`**

```ts
import * as React from 'react';
import {useGridMenuItem} from 'ag-grid-react';
import {
  AdaptableReactMenuItemProps,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-react-aggrid';

type AnyMenuContext = ColumnMenuContext | ContextMenuContext;

export type ThemeToggleMenuItemProps = AdaptableReactMenuItemProps<AnyMenuContext>;

export const ThemeToggleMenuItem = (props: ThemeToggleMenuItemProps) => {
  // Opt-in to AG Grid's default click / keyboard / hover behaviour so this
  // row dismisses the menu and triggers AdapTable's onClick automatically.
  useGridMenuItem({configureDefaults: () => true});

  const {adaptableApi} = props.menuItemParams;
  const isDark = adaptableApi.themeApi.getCurrentTheme() === 'dark';

  return (
    <div>
      <span
        className="ag-menu-option-part ag-menu-option-icon"
        role="presentation"
      />
      <span className="ag-menu-option-part ag-menu-option-text">
        {props.name}
      </span>
      <span
        className="ag-menu-option-part ag-menu-option-shortcut"
        style={{opacity: 0.7}}>
        {isDark ? 'Dark' : 'Light'}
      </span>
      <span className="ag-menu-option-part ag-menu-option-popup-pointer" />
    </div>
  );
};
```



<!-- /framework -->

<!-- framework: angular -->
### Angular

**Example: Column Menu: Standard Custom Items**

Standard custom Column Menu items (Angular)

- **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
- **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (Angular); the files without a marker are shown below:

```text
src/
  app/
    adaptableOptions.ts
    agGridModules.ts     [template]
    app.component.ts     [template]
    app.module.ts        [template]
    columnDefs.ts        [template]
    gridOptions.ts       [template]
    onAdaptableReady.ts  [template]
    rowData.ts           [template]
    styles.css           [template]
  index.html             [template]
  main.ts                [template]
  polyfills.ts           [template]
package.json             [template]
tsconfig.json            [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#angular).

**`src/app/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomColumnMenuContext,
  UserColumnMenuItem,
} from '@adaptabletools/adaptable-angular-aggrid';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Standard Column Menu Items Demo',
  columnMenuOptions: {
    customColumnMenu: (context: CustomColumnMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserColumnMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() === 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {name: 'theme'},
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType === 'date',
        onClick: () => {
          const {themeApi} = adaptableApi;
          themeApi.getCurrentTheme() === 'light'
            ? themeApi.loadDarkTheme()
            : themeApi.loadLightTheme();
        },
      };

      const dashboardMenuItem: UserColumnMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAdaptableMenuStructure,
        '-',
        ...defaultAgGridMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Angular Custom Menu Component

Use `frameworkComponent` on [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want inline switches, multi-button rows, or inputs.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/angular-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration 

In `agInit`, you should read `params.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md), [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md), and any extra fields you supplied on the menu item.

- The `onSetup` function on `AngularFrameworkComponent` is **not** invoked for menu items
- This is because AG Grid owns the component lifecycle

### Providing a Custom Angular Column Menu Item

This is a standard Angular Component that implements `IMenuItemAngularComp` from `ag-grid-angular`.

It must implement two methods:

- `agInit(params)` - called by AG Grid when the menu opens
- `configureDefaults()` - return `true` to opt into AG Grid's default click / keyboard / hover behaviour

```ts
import {ChangeDetectionStrategy, Component} from '@angular/core';
import type {IMenuItemAngularComp} from 'ag-grid-angular';
import type {IMenuItemParams} from 'ag-grid-enterprise';
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable';

type AdaptableMenuItemParams = {
  adaptableApi: AdaptableApi;
  menuContext: ColumnMenuContext | ContextMenuContext;
};

@Component({
  selector: 'app-theme-toggle-menu-item',
  template: `
    <span
      class="ag-menu-option-part ag-menu-option-icon"
      role="presentation"></span>
    <span class="ag-menu-option-part ag-menu-option-text">{{ name }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7;">
      {{ currentTheme === 'dark' ? 'Dark' : 'Light' }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer"></span>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ThemeToggleMenuItemComponent implements IMenuItemAngularComp {
  name = '';
  currentTheme: 'light' | 'dark' = 'light';

  agInit(params: IMenuItemParams): void {
    this.name = params.name ?? '';
    const menuParams = params.menuItemParams as AdaptableMenuItemParams;
    this.currentTheme = menuParams.adaptableApi.themeApi.getCurrentTheme();
  }

  configureDefaults(): boolean {
    return true;
  }
}
```

The menu item component must be declared in your `NgModule`.

```ts {7,12}
import {NgModule} from '@angular/core';
import {AdaptableAngularAgGridModule} from '@adaptabletools/adaptable-angular-aggrid';
import {AgGridModule} from 'ag-grid-angular';
import {BrowserModule} from '@angular/platform-browser';

import {AppComponent} from './app.component';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

@NgModule({
  declarations: [AppComponent, ThemeToggleMenuItemComponent],
  imports: [BrowserModule, AgGridModule, AdaptableAngularAgGridModule],
  bootstrap: [AppComponent],
})
export class AppModule {}
```

In the `customColumnMenu` callback, return a `UserColumnMenuItem` and assign your component class via `frameworkComponent.type`.

```ts {6}
columnMenuOptions: {
  customColumnMenu: (context) => {
    const themeMenuItem: UserColumnMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: {type: ThemeToggleMenuItemComponent},
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
      '-',
      ...context.defaultAgGridMenuStructure,
    ];
  },
},
```

### Anatomy of an Angular Column Menu Item Component

Inside `agInit(params)` the `params` object exposes AG Grid fields (`name`, `icon`, `disabled`, etc.).

AdapTable adds on `params.menuItemParams`:

- `adaptableApi` - the [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` - [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)
- any extra fields you supplied via `menuItemParams` on the User Menu Item

Return `true` from `configureDefaults()` so AG Grid handles click highlighting, dismissing the menu and triggering AdapTable's `onClick`.

**Example: Angular Custom Column Menu Item**

Providing an Angular Component as a Custom Column Menu Item

- This example shows a Custom Angular Component Menu Item at the top of every Column Menu which toggles the current Theme

Demo project (Angular); the files without a marker are shown below:

```text
src/
  app/
    adaptableOptions.ts
    agGridModules.ts                     [template]
    app.component.ts                     [template]
    app.module.ts
    columnDefs.ts                        [template]
    gridOptions.ts                       [template]
    onAdaptableReady.ts                  [template]
    rowData.ts                           [template]
    styles.css                           [template]
    theme-toggle-menu-item.component.ts
  index.html                             [template]
  main.ts                                [template]
  polyfills.ts                           [template]
package.json                             [template]
tsconfig.json                            [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#angular).

**`src/app/adaptableOptions.ts`**

```ts
import {
  AdaptableOptions,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-angular-aggrid';
import {WebFramework} from './rowData';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Menu Item Demo',
  columnMenuOptions: {
    customColumnMenu: (context: CustomColumnMenuContext) => {
      const themeMenuItem: UserColumnMenuItem = {
        menuType: 'User',
        label: 'Toggle Theme',
        frameworkComponent: {type: ThemeToggleMenuItemComponent},
        onClick: () => {
          const themeApi = context.adaptableApi.themeApi;
          themeApi.getCurrentTheme() === 'dark'
            ? themeApi.loadLightTheme()
            : themeApi.loadDarkTheme();
        },
      };
      return [
        themeMenuItem,
        '-',
        ...context.defaultAdaptableMenuStructure,
        '-',
        ...context.defaultAgGridMenuStructure,
      ];
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

**`src/app/theme-toggle-menu-item.component.ts`**

```ts
import {ChangeDetectionStrategy, Component} from '@angular/core';
import type {IMenuItemAngularComp} from 'ag-grid-angular';
import type {IMenuItemParams} from 'ag-grid-enterprise';
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-angular-aggrid';

type AdaptableMenuItemParams = {
  adaptableApi: AdaptableApi;
  menuContext: ColumnMenuContext | ContextMenuContext;
};

@Component({
  standalone: false,
  selector: 'app-theme-toggle-menu-item',
  template: `
    <span
      class="ag-menu-option-part ag-menu-option-icon"
      role="presentation"></span>
    <span class="ag-menu-option-part ag-menu-option-text">{{ name }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7;">
      {{ currentTheme === 'dark' ? 'Dark' : 'Light' }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer"></span>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ThemeToggleMenuItemComponent implements IMenuItemAngularComp {
  name = '';
  currentTheme: 'light' | 'dark' = 'light';

  agInit(params: IMenuItemParams): void {
    this.name = params.name ?? '';
    const menuParams = params.menuItemParams as AdaptableMenuItemParams;
    const theme = menuParams.adaptableApi.themeApi.getCurrentTheme();
    this.currentTheme = theme === 'dark' ? 'dark' : 'light';
  }

  // Tell AG Grid to apply its default click / keyboard / hover behaviour
  // so this row dismisses the menu and runs AdapTable's onClick automatically.
  configureDefaults(): boolean {
    return true;
  }
}
```

**`src/app/app.module.ts`**

```ts
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';

import {AgGridModule} from 'ag-grid-angular';
import {AdaptableAngularAgGridModule} from '@adaptabletools/adaptable-angular-aggrid';
import {AppComponent} from './app.component';
import {ThemeToggleMenuItemComponent} from './theme-toggle-menu-item.component';

@NgModule({
  declarations: [AppComponent, ThemeToggleMenuItemComponent],
  imports: [BrowserModule, AgGridModule, AdaptableAngularAgGridModule],
  providers: [],
  bootstrap: [AppComponent],
  // @ts-ignore FIXME #AFL required only for Codesandbox (which uses an old rendering engine), since Ivy (Angular >9) 'entryComponents' is no longer required in standalone apps
  entryComponents: [ThemeToggleMenuItemComponent],
})
export class AppModule {}
```

<!-- /framework -->

<!-- framework: vue -->
### Vue

**Example: Column Menu: Standard Custom Items**

Standard custom Column Menu items (Vue)

- **Show Dark Theme** / **Show Light Theme** — single action; hidden on row-group columns; disabled on `date` columns
- **Dashboard** — **Show Dashboard** when the Dashboard is hidden; otherwise a sub menu with Hide and Float

Demo project (Vue); the files without a marker are shown below:

```text
public/
  index.html           [template]
src/
  adaptableOptions.ts  [template]
  agGridModules.ts     [template]
  App.vue
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  main.ts              [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  shims-vue.d.ts       [template]
  styles.css           [template]
.babelrc               [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vue).

**`src/App.vue`**

```ts
<script setup lang="ts">
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
  AdaptableOptions,
  CustomColumnMenuContext,
  UserColumnMenuItem,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';

const adaptableOpts: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Standard Column Menu Items Demo',
  stateOptions: {loadState: () => Promise.resolve({})},
  columnMenuOptions: {
    customColumnMenu: (context: CustomColumnMenuContext) => {
      const {
        defaultAgGridMenuStructure,
        defaultAdaptableMenuStructure,
        isRowGroupColumn,
        adaptableColumn,
        adaptableApi,
      } = context;

      const changeThemeMenuItem: UserColumnMenuItem = {
        menuType: 'User',
        label:
          adaptableApi.themeApi.getCurrentTheme() === 'light'
            ? 'Show Dark Theme'
            : 'Show Light Theme',
        icon: {name: 'theme'},
        hidden: isRowGroupColumn,
        disabled: adaptableColumn?.dataType === 'date',
        onClick: () => {
          const {themeApi} = adaptableApi;
          themeApi.getCurrentTheme() === 'light'
            ? themeApi.loadDarkTheme()
            : themeApi.loadLightTheme();
        },
      };

      const dashboardMenuItem: UserColumnMenuItem =
        adaptableApi.dashboardApi.isDashboardHidden()
          ? {
              menuType: 'User',
              label: 'Show Dashboard',
              onClick: () => adaptableApi.dashboardApi.showDashboard(),
            }
          : {
              menuType: 'User',
              label: 'Dashboard',
              subMenuItems: [
                {
                  menuType: 'User',
                  label: 'Hide Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.hideDashboard(),
                },
                {
                  menuType: 'User',
                  label: 'Float Dashboard',
                  onClick: menuContext =>
                    menuContext.adaptableApi.dashboardApi.floatDashboard(),
                },
              ],
            };

      return [
        changeThemeMenuItem,
        dashboardMenuItem,
        '-',
        ...defaultAdaptableMenuStructure,
        '-',
        ...defaultAgGridMenuStructure,
      ];
    },
  },
  initialState: {
    Dashboard: {
      Tabs: [{Name: 'Demo', Toolbars: ['SystemStatus', 'Export']}],
    },
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
</script>

<template>
  <AdaptableProvider
    :gridOptions="gridOptions"
    :adaptableOptions="adaptableOpts"
    :modules="agGridModules"
    @onAdaptableReady="onAdaptableReady">
    <div style="display: flex; flex-direction: column; height: 100vh">
      <AdaptableUI />
      <AdaptableAgGridVue style="flex: 1" />
    </div>
  </AdaptableProvider>
</template>
```

## Vue Custom Menu Component

Use `frameworkComponent` on [`UserColumnMenuItem`](https://www.adaptabletools.com/docs/reference/usercolumnmenuitem.md) when `label`, `icon`, and `onClick` are not enough.

For example if you want a custom layout, extra controls, or live state in the shortcut area.

AG Grid owns the menu lifecycle (open, close, keyboard navigation).

- AdapTable forwards your component to AG Grid's <a href="https://www.ag-grid.com/vue-data-grid/component-menu-item/" target="_blank" rel="noreferrer">Menu Item Component</a> integration
- Use `props.menuItemParams` for [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md) and [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md)

### Providing a Custom Vue Column Menu Item

AG Grid passes menu props to your component; AdapTable adds `menuItemParams` with `adaptableApi` and `menuContext`.

Use `defineExpose({configureDefaults: () => true})` for default AG Grid menu behaviour.

```vue
<script setup lang="ts">
const props = defineProps<{
  name?: string;
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: ColumnMenuContext | ContextMenuContext;
  };
}>();

defineExpose({
  configureDefaults: () => true,
});
</script>

<template>
  <div>
    <span class="ag-menu-option-part ag-menu-option-icon" role="presentation" />
    <span class="ag-menu-option-part ag-menu-option-text">{{
      props.name
    }}</span>
    <span
      class="ag-menu-option-part ag-menu-option-shortcut"
      style="opacity: 0.7">
      {{
        props.menuItemParams.adaptableApi.themeApi.getCurrentTheme() === 'dark'
          ? 'Dark'
          : 'Light'
      }}
    </span>
    <span class="ag-menu-option-part ag-menu-option-popup-pointer" />
  </div>
</template>
```

In `customColumnMenu`, return a `UserColumnMenuItem` with a **factory** that returns your Vue component: `frameworkComponent: () => ThemeToggleMenuItem`.

```ts {6}
columnMenuOptions: {
  customColumnMenu: (context) => {
    const themeMenuItem: UserColumnMenuItem = {
      menuType: 'User',
      label: 'Toggle Theme',
      frameworkComponent: () => ThemeToggleMenuItem,
      onClick: () => {
        const themeApi = context.adaptableApi.themeApi;
        themeApi.getCurrentTheme() === 'dark'
          ? themeApi.loadLightTheme()
          : themeApi.loadDarkTheme();
      },
    };
    return [
      themeMenuItem,
      '-',
      ...context.defaultAdaptableMenuStructure,
      '-',
      ...context.defaultAgGridMenuStructure,
    ];
  },
},
```

`adaptableApi` and `menuContext` are on `props.menuItemParams`.

```ts
const {adaptableApi, menuContext} = props.menuItemParams;
const columnId = menuContext.adaptableColumn?.columnId;
```

### Anatomy of a Vue Column Menu Item Component

AG Grid passes `name`, `icon`, `disabled`, `subMenu`, `shortcut`, and `checked` to your component.

AdapTable adds on `props.menuItemParams`:

- `adaptableApi` - the [`AdaptableApi`](https://www.adaptabletools.com/docs/reference/adaptableapi.md)
- `menuContext` - [`ColumnMenuContext`](https://www.adaptabletools.com/docs/reference/columnmenucontext.md) or [`ContextMenuContext`](https://www.adaptabletools.com/docs/reference/contextmenucontext.md)

`defineExpose({configureDefaults: () => true})` opts your menu into AG Grid's default click / keyboard handling.

**Example: Vue Custom Column Menu Item**

Providing a Vue Component as a Custom Column Menu Item

- This example shows a Custom Vue Component Menu Item at the top of every Column Menu which toggles the current Theme

Demo project (Vue); the files without a marker are shown below:

```text
public/
  index.html               [template]
src/
  agGridModules.ts         [template]
  App.vue
  columnDefs.ts            [template]
  gridOptions.ts           [template]
  main.ts                  [template]
  onAdaptableReady.ts      [template]
  rowData.ts               [template]
  shims-vue.d.ts           [template]
  styles.css               [template]
  ThemeToggleMenuItem.vue
.babelrc                   [template]
package.json               [template]
tsconfig.json              [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vue).

**`src/App.vue`**

```ts
<script setup lang="ts">
import {
  AdaptableProvider,
  AdaptableAgGridVue,
  AdaptableUI,
  AdaptableOptions,
  CustomColumnMenuContext,
  CustomContextMenuContext,
  UserColumnMenuItem,
  UserContextMenuItem,
} from '@adaptabletools/adaptable-vue3-aggrid';

import {onAdaptableReady} from './onAdaptableReady';
import {gridOptions} from './gridOptions';
import {agGridModules} from './agGridModules';
import {WebFramework} from './rowData';
import ThemeToggleMenuItem from './ThemeToggleMenuItem.vue';

const adaptableOpts: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Custom Menu Item Demo',
  stateOptions: {loadState: () => Promise.resolve({})},
  columnMenuOptions: {
    customColumnMenu: (context: CustomColumnMenuContext) => {
      const themeMenuItem: UserColumnMenuItem = {
        menuType: 'User',
        label: 'Toggle Theme',
        frameworkComponent: () => ThemeToggleMenuItem,
        onClick: () => {
          const themeApi = context.adaptableApi.themeApi;
          themeApi.getCurrentTheme() === 'dark'
            ? themeApi.loadLightTheme()
            : themeApi.loadDarkTheme();
        },
      };
      return [
        themeMenuItem,
        '-',
        ...context.defaultAdaptableMenuStructure,
        '-',
        ...context.defaultAgGridMenuStructure,
      ];
    },
  },
  initialState: {
    Theme: {CurrentTheme: 'dark'},
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          Name: 'Standard Layout',
          TableColumns: [
            'name',
            'language',
            'github_stars',
            'license',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'description',
          ],
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
</script>

<template>
  <AdaptableProvider
    :gridOptions="gridOptions"
    :adaptableOptions="adaptableOpts"
    :modules="agGridModules"
    @onAdaptableReady="onAdaptableReady">
    <div style="display: flex; flex-direction: column; height: 100vh">
      <AdaptableUI />
      <AdaptableAgGridVue style="flex: 1" />
    </div>
  </AdaptableProvider>
</template>
```

**`src/ThemeToggleMenuItem.vue`**

```ts
<script setup lang="ts">
import type {
  AdaptableApi,
  ColumnMenuContext,
  ContextMenuContext,
} from '@adaptabletools/adaptable-vue3-aggrid';

type AnyMenuContext = ColumnMenuContext | ContextMenuContext;

const props = defineProps<{
  // AG Grid passes the resolved label text on `name`
  name?: string;
  // AdapTable passes adaptableApi + menuContext via menuItemParams
  menuItemParams: {
    adaptableApi: AdaptableApi;
    menuContext: AnyMenuContext;
  };
}>();

// Opt-in to AG Grid's default click / keyboard / hover behaviour so this
// row dismisses the menu and runs AdapTable's onClick automatically.
defineExpose({
  configureDefaults: () => true,
});
</script>

<template>
  <span class="ag-menu-option-part ag-menu-option-icon" role="presentation" />
  <span class="ag-menu-option-part ag-menu-option-text">
    {{ props.name }}
  </span>
  <span
    class="ag-menu-option-part ag-menu-option-shortcut"
    style="opacity: 0.7">
    {{
      props.menuItemParams.adaptableApi.themeApi.getCurrentTheme() === 'dark'
        ? 'Dark'
        : 'Light'
    }}
  </span>
  <span class="ag-menu-option-part ag-menu-option-popup-pointer" />
</template>
```



<!-- /framework -->
