# Angular Spreadsheet Context Menu

The Spreadsheet context menu provides extensive capabilities identical to what Microsoft Excel has to offer. For example, you can copy and paste content from the clipboard directly into cells, or you can fine-tune the visibility of rows and columns.

The available options in the context menu vary depending on your current selection.

The following example demonstrates the Spreadsheet context menu in action. Right-click a cell, a column header, or row header to see the available options.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/getting-started/source.txt)

## Context Menu Items in Cell

The following table lists the context menu items that are available, regardless of your current cell, row, or column selection.

| Option                 | Description                                            |
| ---------------------- | ------------------------------------------------------ |
| **Copy**               | Copies the selected cells or content to the clipboard. |
| **Cut**                | Cuts the selected cells or content to the clipboard.   |
| **Paste**              | Pastes the clipboard contents into the selected cells. |
| **Merge all**          | Merges the selected cells into a single cell.          |
| **Merge vertically**   | Merges the selected cells vertically.                  |
| **Merge horizontally** | Merges the selected cells horizontally.                |
| **Insert link**        | Inserts a hyperlink into selected cells.               |

## Context Menu Items in Column Header

The following context menu items are available when you right-click a column header (in addition to the cell items):

| Column-only option   | Description                                         |
| -------------------- | --------------------------------------------------- |
| **Add column left**  | Adds a column to the left of the selected columns.  |
| **Add column right** | Adds a column to the right of the selected columns. |
| **Delete column**    | Deletes the selected columns.                       |
| **Hide column**      | Hides the selected columns from view.               |
| **Unhide column**    | Shows the previously hidden column.                 |

## Context Menu Items in Row Header

The following context menu items are available when you right-click a row header (in addition to the cell items):

| Row-only option   | Description                         |
| ----------------- | ----------------------------------- |
| **Add row above** | Adds a row above the selected rows. |
| **Add row below** | Adds a row below the selected rows. |
| **Delete row**    | Deletes the selected rows.          |
| **Hide row**      | Hides the selected rows from view.  |
| **Unhide row**    | Shows the previously hidden rows.   |

## Customizing the Context Menu

The [`contextMenu`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcomponent#contextmenu) event gives you full control over the Spreadsheet context menu. It fires before the menu opens, so you can inspect and modify the [`items`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#items) array before it renders. The [`SpreadsheetContextMenuEvent`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent) also exposes the current selection and the [`targetType`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#targettype), which identifies what the user right-clicked.

These capabilities allow you to customize the context menu in various ways:

<Row>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#adding-custom-items">
      <ComponentTitle>Adding Custom Items</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Extend the context menu with application-specific actions by adding custom items and action callbacks.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#reordering-and-modifying-default-items">
      <ComponentTitle>Reordering and Modifying Default Items</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Rearrange existing items, remove unwanted ones, or insert separators to group related actions.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#replacing-all-context-menu-items">
      <ComponentTitle>Replacing All Context Menu Items</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Replace the entire default menu with a focused, task-specific set of items.</ComponentDescription>
    </Component>
  </Column>
  <Column count={[24,24,12]} style={{marginBottom: "1rem"}}>
    <Component className="tile" href="#preventing-the-context-menu-from-opening">
      <ComponentTitle>Preventing the Context Menu from Opening</ComponentTitle>
      <ComponentDescription style={{padding: "0 10px 10px 10px"}}>Suppress the context menu conditionally based on the target type, selected range, or custom logic.</ComponentDescription>
    </Component>
  </Column>
</Row>

### Adding Custom Items

Adding custom items lets you extend the context menu with actions specific to your application's data or workflow. To achieve this, add a new [`SpreadsheetContextMenuItem`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuitem) to the [`items`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#items) array in the [`contextMenu`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcomponent#contextmenu) event handler, set [`type`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuitem#type) to `'custom'`, and provide an [`action`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuitem#action) callback. The callback receives a [`ContextMenuArgs`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/contextmenuargs) object when the user selects the item.

The [`targetType`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#targettype) property identifies what the user right-clicked—a cell, a row header, or a column header. Use it to show items only in the context where they make sense.

The example below adds context-aware items to the cell menu—**Highlight**, **Insert Date**, **Clear Formatting**, and a conditional **Format as Currency** or **Convert to Uppercase** based on the cell value. The column header menu includes the **Bold Column** and **Clear Column** items.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/context-menu/custom-items/source.txt)

### Reordering and Modifying Default Items

To reorder the default menu items, rearrange the [`items`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#items) array in the `contextMenu` event handler.  Use the [`type`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuitem#type) property to find an existing item and use it as an insertion anchor for custom items. You can also add separators by including an item with `{ type: 'separator' }` set to visually group related actions.

In the example below, **Cut** appears before **Copy**, a separator groups the clipboard actions, and a custom **Clear Cells** item follows.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/context-menu/modify-items/source.txt)

### Replacing All Context Menu Items

Assign a new array to the [`items`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#items) property in the `contextMenu` event handler to replace the default context menu entirely. This approach works well when the default items are not relevant for a particular context and you want a focused, task-specific menu.

The example below replaces the default cell context menu with only the clipboard actions and a custom **Clear Formatting** item. Right-click any cell to see the result.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/context-menu/replace-items/source.txt)

## Preventing the Context Menu from Opening

Call [`preventDefault()`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#preventdefault) on the `contextMenu`event to stop the context menu from opening. Check [`targetType`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent#targettype), the selected range, or any custom condition to apply this selectively.

The example below blocks the context menu for cells that contain a number. Right-click a numeric cell to confirm, then right-click a text cell to see the default menu.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/spreadsheet/context-menu/prevent-menu/source.txt)

## Suggested Links

* [API Reference of the Spreadsheet](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api)
* [API Reference of the `SpreadsheetComponent`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcomponent)
* [API Reference of the `SpreadsheetContextMenuEvent`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuevent)
* [API Reference of the `SpreadsheetContextMenuItem`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/spreadsheetcontextmenuitem)
* [API Reference of the `ContextMenuArgs`](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/api/contextmenuargs)
* [Spreadsheet Appearance](https://www.telerik.com/kendo-angular-ui/components/spreadsheet/appearance)
