From 9f7686061ae4715e087a4cb590e0b47945ae9208 Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Mon, 4 Mar 2024 17:03:26 +0800 Subject: [PATCH 1/3] fix: restore datasource state --- packages/vtable/src/ListTable.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/vtable/src/ListTable.ts b/packages/vtable/src/ListTable.ts index 0ca1eb84e..8a2c9a007 100644 --- a/packages/vtable/src/ListTable.ts +++ b/packages/vtable/src/ListTable.ts @@ -921,6 +921,11 @@ export class ListTable extends BaseTable implements ListTableAPI { * @param sort */ setRecords(records: Array, option?: { sortState?: SortState | SortState[] }): void { + // 释放事件 及 对象 + this.internalProps.dataSource?.release(); + // 过滤掉dataSource的引用 + this.internalProps.releaseList = this.internalProps.releaseList?.filter((item: any) => !item.dataSourceObj); + this.internalProps.dataSource = null; let sort: SortState | SortState[]; if (Array.isArray(option) || (option as any)?.order) { //兼容之前第二个参数为sort的情况 From 85dd1d27c72e710ded9f077e61a207b05af299de Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Mon, 4 Mar 2024 16:42:03 +0800 Subject: [PATCH 2/3] refactor: setRecords clear reference object #1188 --- packages/vtable/examples/list/list.ts | 13 +++++++++---- packages/vtable/src/core/BaseTable.ts | 12 ++++++++++-- .../src/scenegraph/component/table-component.ts | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/vtable/examples/list/list.ts b/packages/vtable/examples/list/list.ts index 656a013b4..44fae61ed 100644 --- a/packages/vtable/examples/list/list.ts +++ b/packages/vtable/examples/list/list.ts @@ -16,7 +16,7 @@ const generatePersons = count => { }; export function createTable() { - const records = generatePersons(10000); + const records = generatePersons(1000000); const columns: VTable.ColumnsDefine = [ { field: '', @@ -203,9 +203,14 @@ export function createTable() { tableInstance.on('change_cell_value', arg => { console.log(arg); }); - // setTimeout(() => { - // tableInstance.addRecord({ id: 333 }, 6); - // }, 3000); + let count = 0; + const intervalId = setTimeout(() => { + count++; + tableInstance.updateOption(option); + if (count > 100) { + clearInterval(intervalId); + } + }, 3000); // tableInstance.on('sort_click', args => { // tableInstance.updateSortState( // { diff --git a/packages/vtable/src/core/BaseTable.ts b/packages/vtable/src/core/BaseTable.ts index 5cbabcdc1..42a1d1c06 100644 --- a/packages/vtable/src/core/BaseTable.ts +++ b/packages/vtable/src/core/BaseTable.ts @@ -2170,7 +2170,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { */ getBottomFrozenRowsHeight(): number { if (this.bottomFrozenRowCount > 0) { - const height = this.getRowsHeight(this.rowCount - this.bottomFrozenRowCount, this.rowCount - 1); + // const height = this.getRowsHeight(this.rowCount - this.bottomFrozenRowCount, this.rowCount - 1);//替换成下面遍历获取高度,鉴于冻结数量有限。否则这里在初始化的时候ClipBodyGroupBeforeRenderContribution.drawShap就先走了这个计算,导致初始化时间加长,而后续计算行高列宽会清除这个计算结果,浪费了性能 + let height = 0; + for (let row = this.rowCount - this.bottomFrozenRowCount; row <= this.rowCount - 1; row++) { + height += this.getRowHeight(row); + } return height; } return 0; @@ -2181,7 +2185,11 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI { */ getRightFrozenColsWidth(): number { if (this.rightFrozenColCount > 0) { - const width = this.getColsWidth(this.colCount - this.rightFrozenColCount, this.colCount - 1); + // const width = this.getColsWidth(this.colCount - this.rightFrozenColCount, this.colCount - 1); // 同getBottomFrozenRowsHeight的原因 + let width = 0; + for (let col = this.colCount - this.rightFrozenColCount; col <= this.colCount - 1; col++) { + width += this.getColWidth(col); + } return width; } return 0; diff --git a/packages/vtable/src/scenegraph/component/table-component.ts b/packages/vtable/src/scenegraph/component/table-component.ts index 18b618dcc..14b129246 100644 --- a/packages/vtable/src/scenegraph/component/table-component.ts +++ b/packages/vtable/src/scenegraph/component/table-component.ts @@ -434,7 +434,7 @@ export class TableComponent { this.frozenShadowLine.setAttributes({ visible: true, x: colX, - height: this.table.getRowsHeight(0, this.table.rowCount - 1) + height: this.table.tableNoFrameHeight }); } } From ded6be8e0d50abf589e0029ade936cc03268d5f1 Mon Sep 17 00:00:00 2001 From: fangsmile <892739385@qq.com> Date: Wed, 27 Mar 2024 10:51:59 +0800 Subject: [PATCH 3/3] docs: update changlog of rush --- .../refactor-setRecords-memory_2024-03-27-02-51.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/@visactor/vtable/refactor-setRecords-memory_2024-03-27-02-51.json diff --git a/common/changes/@visactor/vtable/refactor-setRecords-memory_2024-03-27-02-51.json b/common/changes/@visactor/vtable/refactor-setRecords-memory_2024-03-27-02-51.json new file mode 100644 index 000000000..11beeed15 --- /dev/null +++ b/common/changes/@visactor/vtable/refactor-setRecords-memory_2024-03-27-02-51.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "refactor: setRecords clear reference object #1188\n\n", + "type": "none", + "packageName": "@visactor/vtable" + } + ], + "packageName": "@visactor/vtable", + "email": "892739385@qq.com" +} \ No newline at end of file