Posted 4 August 2020, 9:41 pm EST
ValueChanged events were not executed when undoing after changing the value of a cell in a paste.
How can this be detected?
The system requires the values to be stored in RDS when the value in a cell is changed.
So we want to detect the changes.
Sample implemented in VueJS
HTML
<gc-spread-sheets
@rangeChanged="rangeChanged"
@valueChanged="valueChanged"
@clipboardPasted="clipboardPasted">
...
</gc-spread-sheets>
JavaScript
valueChanged: function (_, values) {
values.newValue = (values.newValue === null) ? undefined : values.newValue
// If the value is not allowed, revert to the previous value
if (values.newValue !== undefined && !String(values.newValue).match(/^([1-9]\d*|0)(\.\d+)?$/)) {
this.dataSource[values.row][key] = values.oldValue
return
}
this.$emit('updateValue', {
numberOfPeople: values.newValue,
})
},
rangeChanged(_, args) {
// Processed only when clear
if (args.action !== 2) {
return
}
args.changedCells.forEach((cells) => {
const values = {
col: cells.col,
row: cells.row,
newValue: undefined
}
this.valueChanged(null, values)
})
},
clipboardPasted(_, args) {
let data = []
const range = args.cellRange
// Convert pasted text into an array
let rowText = args.pasteData.text.split('\n')
for (let i = 0; i < rowText.length; i++) {
data[i] = []
let rowValues = rowText[i].split('\t')
for (let j = 0; j < rowValues.length; j++) {
data[i].push(rowValues[j].trim())
}
}
...
this.valueChanged(null, values)
}
