From 022b4e212a352fd6ba8a0742f5b897f4b2927419 Mon Sep 17 00:00:00 2001 From: Rui-Sun Date: Wed, 25 Sep 2024 11:54:35 +0800 Subject: [PATCH] fix: fix estimate position in updateAutoRow() #2494 --- ...tom-frozen-updateRow_2024-09-25-03-54.json | 10 +++++ .../list-aggregation-deleteRecord.ts | 43 +++++++++++-------- .../update-position/update-auto-row.ts | 18 +++++++- 3 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 common/changes/@visactor/vtable/fix-bottom-frozen-updateRow_2024-09-25-03-54.json diff --git a/common/changes/@visactor/vtable/fix-bottom-frozen-updateRow_2024-09-25-03-54.json b/common/changes/@visactor/vtable/fix-bottom-frozen-updateRow_2024-09-25-03-54.json new file mode 100644 index 000000000..a9abac4b7 --- /dev/null +++ b/common/changes/@visactor/vtable/fix-bottom-frozen-updateRow_2024-09-25-03-54.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@visactor/vtable", + "comment": "fix: fix estimate position in updateAutoRow() #2494", + "type": "none" + } + ], + "packageName": "@visactor/vtable" +} \ No newline at end of file diff --git a/packages/vtable/examples/list-analysis/list-aggregation-deleteRecord.ts b/packages/vtable/examples/list-analysis/list-aggregation-deleteRecord.ts index bcb289bd5..92ac26241 100644 --- a/packages/vtable/examples/list-analysis/list-aggregation-deleteRecord.ts +++ b/packages/vtable/examples/list-analysis/list-aggregation-deleteRecord.ts @@ -1,4 +1,5 @@ import * as VTable from '../../src'; +import { bindDebugTool } from '../../src/scenegraph/debug-tool'; import { AggregationType } from '../../src/ts-types'; const CONTAINER_ID = 'vTable'; const generatePersons = count => { @@ -156,7 +157,7 @@ export function createTable() { isShowOverflowTextTooltip: true }, frozenColCount: 1, - // bottomFrozenRowCount: 2, + bottomFrozenRowCount: 2, rightFrozenColCount: 1, overscrollBehavior: 'none', autoWrapText: true, @@ -221,25 +222,29 @@ export function createTable() { // widthMode: 'adaptive' }; const tableInstance = new VTable.ListTable(document.getElementById(CONTAINER_ID), option); - // tableInstance.deleteRecords([0]); - tableInstance.updateRecords( - [ - { - id: 10, - email1: '10@xxx.com', - name: '小明10', - lastName: '王', - date1: '2022年9月1日', - tel: '000-0000-0000', - sex: 'girl', - work: 'front-end engineer10', - city: 'beijing', - salary: 60 - } - ], - [0] - ); + tableInstance.deleteRecords([0]); + // tableInstance.updateRecords( + // [ + // { + // id: 10, + // email1: '10@xxx.com', + // name: '小明10', + // lastName: '王', + // date1: '2022年9月1日', + // tel: '000-0000-0000', + // sex: 'girl', + // work: 'front-end engineer10', + // city: 'beijing', + // salary: 60 + // } + // ], + // [0] + // ); window.tableInstance = tableInstance; + + bindDebugTool(tableInstance.scenegraph.stage, { + customGrapicKeys: ['col', 'row'] + }); tableInstance.on('change_cell_value', arg => { console.log(arg); }); diff --git a/packages/vtable/src/scenegraph/group-creater/progress/update-position/update-auto-row.ts b/packages/vtable/src/scenegraph/group-creater/progress/update-position/update-auto-row.ts index dda7e6aff..99e6906b1 100644 --- a/packages/vtable/src/scenegraph/group-creater/progress/update-position/update-auto-row.ts +++ b/packages/vtable/src/scenegraph/group-creater/progress/update-position/update-auto-row.ts @@ -34,7 +34,7 @@ export function updateAutoRow( } } else { // 估计位置 - y = table.getRowsHeight(table.frozenRowCount, cellGroup.row - 1); + y = getEstimatePosition(cellGroup.row, table); } if (isValid(y)) { cellGroup.setAttribute('y', y); @@ -61,7 +61,7 @@ export function updateAutoRow( } } else { // 估计位置 - y = table.getRowsHeight(table.frozenRowCount, cellGroup.row - 1); + y = getEstimatePosition(cellGroup.row, table); // console.log('估计位置', table.getRowsHeight(table.frozenRowCount, cellGroup.row)); } if (isValid(y)) { @@ -94,3 +94,17 @@ export function updateAutoRow( // y = child.attribute.y + child.attribute.height; // }); } + +// 获取预估位置 +function getEstimatePosition(row: number, table: BaseTableAPI) { + let y; + if (row < table.frozenRowCount) { + y = table.getRowsHeight(0, row - 1); + } else if (row >= table.rowCount - table.bottomFrozenRowCount) { + y = table.getRowsHeight(table.rowCount - table.bottomFrozenRowCount, row - 1); + } else { + y = table.getRowsHeight(table.frozenRowCount, row - 1); + } + + return y; +}