Articles in this section
Category / Section

How to disable editing in a particular columns in the Spreadsheet?

1 min read

This knowledge base explains, how to disable editing in a particular column in the JavaScript Spreadsheet

You can use the cellEdit event to prevent editing in a particular column. You need to define the “cancel” argument as “false” in the “cellEdit” event to prevent editing. In the below code we have disabled editing for the “E” column.

 

JavaScript Solution

 

[HTML]

 

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

 

[TS]

 

//Initialize Spreadsheet component        
let spreadsheet: Spreadsheet = new Spreadsheet({
            sheets: [
                {
                    name: 'Car Sales Report',
                    ranges: [{ dataSource: (dataSource as any).defaultData }], // you can refer this datasource in this link https://ej2.syncfusion.com/javascript/demos/spreadsheet/default/datasource.js
                    rows: [
                        {
                            index: 30,
                            cells: [
                                { index: 4, value: 'Total Amount:', style: { fontWeight: 'bold', textAlign: 'right' } },
                                { formula: '=SUM(F2:F30)', style: { fontWeight: 'bold' } },
                            ]
                        }],
                    columns: [
                        { width: 180 }, { width: 130 }, { width: 130 }, { width: 180 },
                        { width: 130 }, { width: 120 }
                    ]
                }] , 
             created: (): void => {
         spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1');
            spreadsheet.numberFormat('$#,##0.00', 'F2:F31');
        },
              // Triggers before going to the editing mode.
              cellEdit: (args: CellEditEventArgs): void => {
                // Preventing the editing in E column.
                if (args.address.includes('E')) { args.cancel = true; }
              }
        });
 
        //Render initialized Spreadsheet component
        spreadsheet.appendTo('#spreadsheet');
 

 

 

Sample:

https://stackblitz.com/edit/48ojqc-utnmnn?file=index.ts

 

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