You can edit the contents of a cell directly in the cell or by typing in the formula bar. By default, the editing feature is enabled in the spreadsheet. Use the allowEditing
property to enable or disable the editing feature.
You can start editing by one of the following ways,
F2
key to edit the active cell.BACKSPACE
or SPACE
key to clear the cell content and start the edit mode.startEdit
method.If the cell is in editable state, you can save the edited cell by one of the following ways,
Enter
or Tab
keys to save the edited cell content.endEdit
method.To cancel the editing without saving the changes, you can use one of the following ways,
ESCAPE
key, this will remove the editable state and update the unchanged cell content.closeEdit
method.The following sample shows how to prevent the editing and cell save. Here E
column prevent the editing by using cancel argument as true in cellEdit
event. In D
column, prevent saving the edited changes by using cancel argument as true in beforeCellSave
and use closeEdit
method in spreadsheet.
<template>
<ejs-spreadsheet ref="spreadsheet" :created="created" :showFormulaBar="false" :cellEdit="cellEdit" :beforeCellSave="beforeCellSave">
<e-sheets>
<e-sheet selectedRange="E11">
<e-ranges>
<e-range :dataSource="dataSource"></e-range>
</e-ranges>
<e-columns>
<e-column :width=120></e-column>
<e-column :width=180></e-column>
<e-column :width=100></e-column>
<e-column :width=120></e-column>
<e-column :width=120></e-column>
</e-columns>
<e-rows>
<e-row index="10">
<e-cells>
<e-cell index="3" value="Total Amount:" style="fontStyle"></e-cell>
<e-cell formula="=SUM(E2:E10)"></e-cell>
</e-cells>
</e-row>
</e-rows>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>
</template>
<script>
import Vue from "vue";
import { SpreadsheetPlugin } from "@syncfusion/ej2-vue-spreadsheet";
import { data } from './data.js';
Vue.use(SpreadsheetPlugin);
export default {
data: () => {
return {
dataSource: data,
fontStyle: { fontWeight: 'bold' }
}
},
methods: {
created: function () {
var spreadsheet = this.$refs.spreadsheet;
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:E1');
spreadsheet.cellFormat({ textAlign: 'center' }, 'A2:A10');
spreadsheet.cellFormat({ textAlign: 'center' }, 'C2:C10');
spreadsheet.numberFormat('$#,##0.00', 'D2:D10');
spreadsheet.numberFormat('$#,##0.00', 'E2:E11');
},
cellEdit: function (args) {
// Preventing the editing in 5th(Amount) column.
if (args.address.includes('E')) { args.cancel = true; }
},
beforeCellSave: function (args) {
var spreadsheet = this.$refs.spreadsheet;
// Prevent saving the edited changes in 4th(Rate) column.
if (args.address.includes('D')) {
args.cancel = true;
// Manually removes the editable state without saving the changes. Use `endEdit` method if you want to save the changes.
spreadsheet.closeEdit();
}
}
},
}
</script>
<style>
@import "../node_modules/@syncfusion/ej2-vue-spreadsheet/styles/material.css";
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-grids/styles/material.css';
@import "../node_modules/@syncfusion/ej2-spreadsheet/styles/material.css";
</style>
define(["require", "exports"], function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.data = [
{
'Item Code': 'I231',
'Item Name': 'Chinese Combo Noodle',
'Quantity': 2,
'Rate': 125,
'Amount': '=PRODUCT(C2,D2)'
},
{
'Item Code': 'I245',
'Item Name': 'Chinese Combo Rice',
'Quantity': 3,
'Rate': 125,
'Amount': '=PRODUCT(C3,D3)'
},
{
'Item Code': 'I237',
'Item Name': 'Amritsari Chola',
'Quantity': 2,
'Rate': 225,
'Amount': '=PRODUCT(C4,D4)'
},
{
'Item Code': 'I291',
'Item Name': 'Asian Mixed Entree Platt',
'Quantity': 3,
'Rate': 165,
'Amount': '=PRODUCT(C5,D5)'
},
{
'Item Code': 'I268',
'Item Name': 'Chinese Combo Chicken',
'Quantity': 3,
'Rate': 125,
'Amount': '=PRODUCT(C6,D6)'
},
{
'Item Code': 'I251',
'Item Name': 'Chivas Regal',
'Quantity': 1,
'Rate': 325,
'Amount': '=PRODUCT(C7,D7)'
},
{
'Item Code': 'I256',
'Item Name': 'Chicken Drumsticks',
'Quantity': 2,
'Rate': 180,
'Amount': '=PRODUCT(C8,D8)'
},
{
'Item Code': 'I232',
'Item Name': 'Manchow Soup',
'Quantity': 2,
'Rate': 160,
'Amount': '=PRODUCT(C9,D9)'
},
{
'Item Code': 'I290',
'Item Name': 'Schezuan Chicken',
'Quantity': 3,
'Rate': 180,
'Amount': '=PRODUCT(C10,D10)'
}
];
});
You can refer to our Vue Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our Vue Spreadsheet example to knows how to present and manipulate data.