diff --git a/packages/vtable/examples/editor/date-editor.ts b/packages/vtable/examples/editor/date-editor.ts index ac5ff3ce7..f7561fd89 100644 --- a/packages/vtable/examples/editor/date-editor.ts +++ b/packages/vtable/examples/editor/date-editor.ts @@ -190,5 +190,8 @@ export function createTable() { tableInstance.on('initialized', args => { console.log('initialized'); }); + tableInstance.on('change_cell_value', arg => { + console.log(arg); + }); window.tableInstance = tableInstance; } diff --git a/packages/vtable/src/PivotTable.ts b/packages/vtable/src/PivotTable.ts index 465d25643..cb7142f20 100644 --- a/packages/vtable/src/PivotTable.ts +++ b/packages/vtable/src/PivotTable.ts @@ -1728,13 +1728,15 @@ export class PivotTable extends BaseTable implements PivotTableAPI { const newHeight = computeRowHeight(row, 0, this.colCount - 1, this); this.scenegraph.updateRowHeight(row, newHeight - oldHeight); } - this.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { - col, - row, - rawValue, - currentValue: oldValue, - changedValue: newValue - }); + if (oldValue !== newValue) { + this.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { + col, + row, + rawValue, + currentValue: oldValue, + changedValue: newValue + }); + } this.scenegraph.updateNextFrame(); } } @@ -1797,14 +1799,16 @@ export class PivotTable extends BaseTable implements PivotTableAPI { newValue = parseFloat(value); } this._changeCellValueToDataSet(startCol + j, startRow + i, oldValue, newValue); - - this.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { - col: startCol + j, - row: startRow + i, - rawValue, - currentValue: oldValue, - changedValue: this.getCellOriginValue(startCol + j, startRow + i) - }); + const changedValue = this.getCellOriginValue(startCol + j, startRow + i); + if (changedValue !== oldValue) { + this.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { + col: startCol + j, + row: startRow + i, + rawValue, + currentValue: oldValue, + changedValue + }); + } } } pasteColEnd = Math.max(pasteColEnd, thisRowPasteColEnd); diff --git a/packages/vtable/src/core/record-helper.ts b/packages/vtable/src/core/record-helper.ts index cc185e0d3..9c105d9e1 100644 --- a/packages/vtable/src/core/record-helper.ts +++ b/packages/vtable/src/core/record-helper.ts @@ -90,13 +90,16 @@ export function listTableChangeCellValue( const newHeight = computeRowHeight(row, 0, table.colCount - 1, table); table.scenegraph.updateRowHeight(row, newHeight - oldHeight); } - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { - col, - row, - rawValue: beforeChangeValue, - currentValue: oldValue, - changedValue: table.getCellOriginValue(col, row) - }); + const changedValue = table.getCellOriginValue(col, row); + if (oldValue !== changedValue) { + table.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { + col, + row, + rawValue: beforeChangeValue, + currentValue: oldValue, + changedValue + }); + } table.scenegraph.updateNextFrame(); } } @@ -189,13 +192,16 @@ export function listTableChangeCellValues( } else { table.dataSource.changeFieldValue(value, recordIndex, field, startCol + j, startRow + i, table); } - table.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { - col: startCol + j, - row: startRow + i, - rawValue: beforeChangeValue, - currentValue: oldValue, - changedValue: table.getCellOriginValue(startCol + j, startRow + i) - }); + const changedValue = table.getCellOriginValue(startCol + j, startRow + i); + if (oldValue !== changedValue) { + table.fireListeners(TABLE_EVENT_TYPE.CHANGE_CELL_VALUE, { + col: startCol + j, + row: startRow + i, + rawValue: beforeChangeValue, + currentValue: oldValue, + changedValue + }); + } } } pasteColEnd = Math.max(pasteColEnd, thisRowPasteColEnd);