From 47b705b9b82aa151537ed650bf1a669b550e0969 Mon Sep 17 00:00:00 2001 From: taiiiyang <781547101@qq.com> Date: Sat, 21 Dec 2024 11:48:11 +0800 Subject: [PATCH 1/2] feat: fire CHANGE_CELL_VALUE event when real update --- packages/vtable/src/PivotTable.ts | 16 ++++++----- packages/vtable/src/core/record-helper.ts | 34 +++++++++++++---------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/vtable/src/PivotTable.ts b/packages/vtable/src/PivotTable.ts index 465d25643..96cc8c641 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(); } } 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); From 9611946d95fde34be4d54cf8d8972c55272ce77c Mon Sep 17 00:00:00 2001 From: taiiiyang <781547101@qq.com> Date: Sat, 21 Dec 2024 12:21:47 +0800 Subject: [PATCH 2/2] feat: pivot table change cells value when real update --- packages/vtable/examples/editor/date-editor.ts | 3 +++ packages/vtable/src/PivotTable.ts | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) 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 96cc8c641..cb7142f20 100644 --- a/packages/vtable/src/PivotTable.ts +++ b/packages/vtable/src/PivotTable.ts @@ -1799,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);