Articles in this section
Category / Section

How to prevent sheet rename action in JavaScript Spreadsheet

1 min read

This article explains how to prevent the sheet rename action in the JavaScript Spreadsheet. To achieve this requirement, you can use the removeContextMenuItems method to remove the rename item from the context menu. Additionally, you have to prevent the sheet rename action at the UI level by setting args.cancel as true in the actionBegin event.

[HTML]

<div id="spreadsheet"></div> 

[TS]

import { closest } from '@syncfusion/ej2-base';
import { BeforeOpenCloseMenuEventArgs } from '@syncfusion/ej2-navigations';
import { Spreadsheet } from '@syncfusion/ej2-spreadsheet';

let spreadsheet: Spreadsheet = new Spreadsheet({
 actionBegin(args: any) {
   //Prevent the sheet rename action by checking the action name in the actionBegin event.
   if (args.action == 'renameSheet') {
     args.cancel = true;
   }
 },
 contextMenuBeforeOpen: (args: BeforeOpenCloseMenuEventArgs): void => {
   //Check whether the sheet tab context-menu is opening or not.
   if (closest(args.event.target as Element, '.e-toolbar-item')) {
     //Remove the Rename item from the context menu using the removeContextMenuItems method.
     spreadsheet.removeContextMenuItems(['Rename']);
   }
 },
});

spreadsheet.appendTo('#spreadsheet');

Sample Link:

Refer to the working sample for additional details and implementation: Sample

Output:

Prevent_rename.png

Documentation link:

https://ej2.syncfusion.com/documentation/spreadsheet/context-menu#remove-context-menu-items

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied