Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: optimize row height update when useOneRowHeightFillAll #1920

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/vtable/src/ListTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.editorManager = new EditManeger(this);
}
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

if (options.dataSource) {
_setDataSource(this, options.dataSource);
Expand Down Expand Up @@ -164,6 +165,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.internalProps.headerHelper.setTableColumnsEditor();
this._hasAutoImageColumn = undefined;
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
this.scenegraph.clearCells();
this.headerStyleCache = new Map();
this.bodyStyleCache = new Map();
Expand All @@ -190,6 +192,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.internalProps.columns = header;
this.options.header = header;
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
//需要异步等待其他事情都完成后再绘制
this.renderAsync();
}
Expand Down Expand Up @@ -408,6 +411,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
this.transpose = options.transpose ?? false;
// 更新表头
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

// this.hasMedia = null; // 避免重复绑定
// 清空目前数据
Expand Down Expand Up @@ -459,6 +463,7 @@ export class ListTable extends BaseTable implements ListTableAPI {
pagination.perPageCount &&
(this.pagination.perPageCount = pagination.perPageCount || this.pagination.perPageCount);
this.internalProps.layoutMap.clearCellRangeMap();
this.internalProps.useOneRowHeightFillAll = false;
// 清空单元格内容
this.scenegraph.clearCells();
//数据源缓存数据更新
Expand Down Expand Up @@ -796,6 +801,7 @@ export class ListTable extends BaseTable implements ListTableAPI {

this.clearCellStyleCache();
this.internalProps.layoutMap.clearCellRangeMap();
this.internalProps.useOneRowHeightFillAll = false;
this.scenegraph.updateHierarchyIcon(col, row);
this.scenegraph.updateRow(diffPositions.removeCellPositions, diffPositions.addCellPositions);
if (checkHasChart) {
Expand Down Expand Up @@ -891,6 +897,7 @@ export class ListTable extends BaseTable implements ListTableAPI {

// clear cell range cache
this.internalProps.layoutMap.clearCellRangeMap();
this.internalProps.useOneRowHeightFillAll = false;
this.scenegraph.sortCell();
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/vtable/src/PivotChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export class PivotChart extends BaseTable implements PivotChartAPI {

this.internalProps.layoutMap = new PivotHeaderLayoutMap(this, this.dataset, columnDimensionTree, rowDimensionTree);
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
// this.internalProps.frozenColCount = this.options.frozenColCount || this.rowHeaderLevelCount;
// 生成单元格场景树
this.scenegraph.createSceneGraph();
Expand Down Expand Up @@ -438,6 +439,7 @@ export class PivotChart extends BaseTable implements PivotChartAPI {

// 更新表头
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

// this.hasMedia = null; // 避免重复绑定
// 清空目前数据
Expand Down Expand Up @@ -760,6 +762,7 @@ export class PivotChart extends BaseTable implements PivotChartAPI {
// 清空单元格内容
this.scenegraph.clearCells();
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
// 生成单元格场景树
this.scenegraph.createSceneGraph();
this.render();
Expand Down Expand Up @@ -1387,6 +1390,7 @@ export class PivotChart extends BaseTable implements PivotChartAPI {

// 更新表头
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

// 清空单元格内容
this.scenegraph.clearCells();
Expand Down
4 changes: 4 additions & 0 deletions packages/vtable/src/PivotTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
}

this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
this.stateManager.initCheckedState(records);
// this.internalProps.frozenColCount = this.options.frozenColCount || this.rowHeaderLevelCount;

Expand Down Expand Up @@ -392,6 +393,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {

// 更新表头
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

// this.hasMedia = null; // 避免重复绑定
// 清空目前数据
Expand Down Expand Up @@ -983,6 +985,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {
// 清空单元格内容
this.scenegraph.clearCells();
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
// 生成单元格场景树
this.scenegraph.createSceneGraph();
this.render();
Expand Down Expand Up @@ -1479,6 +1482,7 @@ export class PivotTable extends BaseTable implements PivotTableAPI {

// 更新表头
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;

// 清空单元格内容
this.scenegraph.clearCells();
Expand Down
1 change: 1 addition & 0 deletions packages/vtable/src/core/BaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,7 @@ export abstract class BaseTable extends EventTarget implements BaseTableAPI {
renderWithRecreateCells() {
const oldHoverState = { col: this.stateManager.hover.cellPos.col, row: this.stateManager.hover.cellPos.row };
this.refreshHeader();
this.internalProps.useOneRowHeightFillAll = false;
this.scenegraph.clearCells();
this.clearCellStyleCache();
this.scenegraph.createSceneGraph();
Expand Down
1 change: 1 addition & 0 deletions packages/vtable/src/layout/pivot-header-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,7 @@ export class PivotHeaderLayoutMap implements LayoutMapAPI {

setPagination(pagination: IPagination): void {
this.clearCellRangeMap();
this._table.internalProps.useOneRowHeightFillAll = false;
this.pagination = pagination;

if (
Expand Down
4 changes: 4 additions & 0 deletions packages/vtable/src/layout/row-height-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ export class NumberRangeMap {
put(position: number, newValue: number) {
if (this.data.has(position)) {
const oldValue = this.data.get(position);

if (oldValue === newValue) {
return;
}
this.data.set(position, newValue);
const difference = newValue - oldValue;
this.totalSum += difference;
Expand Down
4 changes: 4 additions & 0 deletions packages/vtable/src/scenegraph/layout/compute-row-height.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,17 @@ function fillRowsHeight(
table: BaseTableAPI,
newHeights: number[] | undefined
) {
if (table.internalProps.useOneRowHeightFillAll) {
return;
}
for (let row = startRow; row <= endRow; row++) {
if (newHeights) {
newHeights[row] = height;
} else {
table._setRowHeight(row, height);
}
}
table.internalProps.useOneRowHeightFillAll = true;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/vtable/src/scenegraph/scenegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ export class Scenegraph {

updateRow(removeCells: CellAddress[], addCells: CellAddress[], updateCells: CellAddress[] = []) {
this.table.internalProps.layoutMap.clearCellRangeMap();
this.table.internalProps.useOneRowHeightFillAll = false;
const addRows = deduplication(addCells.map(cell => cell.row)).sort((a, b) => a - b);
const updateRows = deduplication(updateCells.map(cell => cell.row)).sort((a, b) => a - b);
//这个值是后续为了autoFillHeight判断逻辑中用到的 判断是否更新前是未填满的情况
Expand Down
1 change: 1 addition & 0 deletions packages/vtable/src/state/cell-move/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function endMoveCol(state: StateManager) {

// 更新状态
if (moveContext) {
state.table.internalProps.useOneRowHeightFillAll = false;
state.table.internalProps.layoutMap.clearCellRangeMap();
const sourceMergeInfo = state.table.getCellRange(state.columnMove.colSource, state.columnMove.rowSource);
const targetMergeInfo = state.table.getCellRange(state.columnMove.colTarget, state.columnMove.rowTarget);
Expand Down
1 change: 1 addition & 0 deletions packages/vtable/src/state/sort/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function dealSort(col: number, row: number, table: ListTableAPI, event: E
}

// clear cell range cache
table.internalProps.useOneRowHeightFillAll = false;
table.internalProps.layoutMap.clearCellRangeMap();

table.scenegraph.sortCell();
Expand Down
3 changes: 3 additions & 0 deletions packages/vtable/src/ts-types/base-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export interface IBaseTableProtected {
* 设置为 'none' 时, 表格滚动到顶部/底部时, 不再触发父容器滚动
* */
overscrollBehavior?: 'auto' | 'none';

// 已使用一行的高度填充所有行
useOneRowHeightFillAll?: boolean;
}
export interface BaseTableConstructorOptions {
// /** 指定表格的行数 */
Expand Down
Loading