Context menu in Angular Spreadsheet component
3 Jul 202410 minutes to read
Context Menu is used to improve user interaction with Spreadsheet using the popup menu. This will open when right-clicking on Cell/Column Header/Row Header/ Pager in the Spreadsheet. You can use enableContextMenu
property to enable/disable context menu.
The default value for the
enableContextMenu
property istrue
.
Context Menu Items in Row Cell
Please find the table below for default context menu items and their actions.
Context Menu items | Action |
---|---|
Cut |
Cut the selected cells data to the clipboard, you can select a cell where you want to move the data. |
Copy |
Copy the selected cells data to the clipboard, so that you can paste it to somewhere else. |
Paste |
Paste the data from clipboard to spreadsheet. |
Paste Special |
Values - Paste the data values from clipboard to spreadsheet. Formats - Paste the data formats from clipboard to spreadsheet. |
Filter |
Perform filtering to the selected cells based on an active cell’s value. |
Sort |
Perform sorting to the selected range of cells by ascending or descending. |
Hyperlink |
Create a link in the spreadsheet to navigate to web links or cell reference within the sheet or other sheets in the Spreadsheet. |
Context Menu Items in Row Header / Column Header
Please find the table below for default context menu items and their actions.
Context Menu items | Action |
---|---|
Cut |
Cut the selected row/column header data to the clipboard, you can select a cell where you want to move the data. |
Copy |
Copy the selected row/column header data to the clipboard, so that you can paste it to somewhere else. |
Paste |
Paste the data from clipboard to spreadsheet. |
Paste Special |
Values - Paste the data values from clipboard to spreadsheet. Formats - Paste the data formats from clipboard to spreadsheet. |
Insert Rows / Insert Columns
|
Insert new rows or columns into the worksheet. |
Delete Rows / Delete Columns
|
Delete existing rows or columns from the worksheet. |
Hide Rows / Hide Columns
|
Hide the or and columns. |
UnHide Rows / UnHide Columns
|
Show the hidden rows or columns. |
Context Menu Items in Pager
Please find the table below for default context menu items and their actions.
Context Menu items | Action |
---|---|
Insert |
Insert a new worksheet in front of an existing worksheet in the spreadsheet. |
Delete |
Delete the selected worksheet from the spreadsheet. |
Rename |
Rename the selected worksheet. |
Protect Sheet |
Prevent unwanted changes from others by limiting their ability to edit. |
Hide |
Hide the selected worksheet. |
Context Menu Customization
You can perform the following context menu customization options in the spreadsheet
- Add Context Menu Items
- Remove Context Menu Items
- Enable/Disable Context Menu Items
Add Context Menu Items
You can add the custom items in context menu using the addContextMenuItems
in contextmenuBeforeOpen
event
In this demo, Custom Item is added after the Paste item in the context menu.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet';
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (contextMenuBeforeOpen)="contextMenuBeforeOpen($event)">
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
public spreadsheetObj: SpreadsheetComponent | undefined;
contextMenuBeforeOpen(args: any) {
if (args.element.id === this.spreadsheetObj!.element.id + '_contextmenu') {
// To add context menu items.
this.spreadsheetObj!.addContextMenuItems([{ text: 'Custom Item' }], 'Paste Special', false); //To pass the items, Item before / after that the element to be inserted, Set false if the items need to be inserted before the text.
}
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Remove Context Menu Items
You can remove the items in context menu using the removeContextMenuItems
in contextmenuBeforeOpen
event
In this demo, Insert Column item has been removed from the row/column header context menu.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (contextMenuBeforeOpen)="contextMenuBeforeOpen()">
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
contextMenuBeforeOpen() {
// To add context menu items.
this.spreadsheetObj!.removeContextMenuItems(["Insert Column"], false); //Items that needs to be removed, Set `true` if the given `text` is a unique id.
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Enable/Disable Context Menu Items
You can enable/disable the items in context menu using the enableContextMenuItems
in contextmenuBeforeOpen
event
In this demo, Rename item is disabled in the pager context menu.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (contextMenuBeforeOpen)="contextMenuBeforeOpen()">
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
contextMenuBeforeOpen() {
// To add context menu items.
this.spreadsheetObj!.enableContextMenuItems(['Rename'], false, false); // Contextmenu Items that needs to be enabled / disabled, Set true / false to enable / disable the menu items, Set true if the given text is a unique id.
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Note
You can refer to our Angular Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our Angular Spreadsheet example to knows how to present and manipulate data.