How to disable editing in a particular columns in the Spreadsheet?
This article 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 code below, 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
Conclusion
We hope you enjoyed learning about how to disable editing in a particular columns in the Spreadsheet.
You can refer to our JavaScript Spreadsheet page to learn about its other groundbreaking feature representations. You can also explore our JavaScript Spreadsheet Documentation to understand how to manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!