Skip to content

Commit

Permalink
Merge pull request #3173 from taiiiyang/feat/change-cell-value-when-u…
Browse files Browse the repository at this point in the history
…pdate

Feat/change cell value when update
  • Loading branch information
fangsmile authored Dec 23, 2024
2 parents 8aca8b2 + 9611946 commit 04bcb0d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
3 changes: 3 additions & 0 deletions packages/vtable/examples/editor/date-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
34 changes: 19 additions & 15 deletions packages/vtable/src/PivotTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
34 changes: 20 additions & 14 deletions packages/vtable/src/core/record-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 04bcb0d

Please sign in to comment.