From b29915d896871ae6246613b330b59efd1d59b20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=BF=E7=8F=82?= Date: Tue, 18 Jul 2023 19:33:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(table-sheet):=20=E4=BF=AE=E5=A4=8D=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=A1=A8=E8=8E=B7=E5=8F=96=E5=88=B0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E9=99=85=E6=B8=B2=E6=9F=93=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E9=AB=98=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts | 4 ++++ packages/s2-core/src/facet/base-facet.ts | 7 ++----- packages/s2-core/src/facet/pivot-facet.ts | 5 +++++ packages/s2-core/src/facet/table-facet.ts | 7 +++++++ packages/s2-core/src/sheet-type/pivot-sheet.ts | 4 ++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts b/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts index 626d8b0eb7..a12e0282a9 100644 --- a/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts +++ b/packages/s2-core/__tests__/unit/sheet-type/table-sheet-spec.ts @@ -214,4 +214,8 @@ describe('TableSheet Tests', () => { expect(onDestroy).toHaveBeenCalledTimes(1); }); + + test('should get content height', () => { + expect(s2.getContentHeight()).toEqual(120); + }); }); diff --git a/packages/s2-core/src/facet/base-facet.ts b/packages/s2-core/src/facet/base-facet.ts index c665ff7a11..122ca8b64a 100644 --- a/packages/s2-core/src/facet/base-facet.ts +++ b/packages/s2-core/src/facet/base-facet.ts @@ -126,6 +126,8 @@ export abstract class BaseFacet { protected abstract doLayout(): LayoutResult; + public abstract getContentHeight(): number; + public abstract getViewCellHeights( layoutResult: LayoutResult, ): ViewCellHeights; @@ -255,11 +257,6 @@ export abstract class BaseFacet { }; } - public getContentHeight(): number { - const { rowsHierarchy, colsHierarchy } = this.layoutResult; - return rowsHierarchy.height + colsHierarchy.height; - } - public updateScrollOffset(offsetConfig: OffsetConfig) { if (offsetConfig.rowHeaderOffsetX?.value !== undefined) { if (offsetConfig.rowHeaderOffsetX?.animate) { diff --git a/packages/s2-core/src/facet/pivot-facet.ts b/packages/s2-core/src/facet/pivot-facet.ts index bf234122aa..559a2a43a8 100644 --- a/packages/s2-core/src/facet/pivot-facet.ts +++ b/packages/s2-core/src/facet/pivot-facet.ts @@ -42,6 +42,11 @@ export class PivotFacet extends BaseFacet { return this.spreadsheet.theme.rowCell.cell; } + public getContentHeight(): number { + const { rowsHierarchy, colsHierarchy } = this.layoutResult; + return rowsHierarchy.height + colsHierarchy.height; + } + protected doLayout(): LayoutResult { // 1、layout all nodes in rowHeader and colHeader const { leafNodes: rowLeafNodes, hierarchy: rowsHierarchy } = diff --git a/packages/s2-core/src/facet/table-facet.ts b/packages/s2-core/src/facet/table-facet.ts index 19e57c7b76..f605726e6a 100644 --- a/packages/s2-core/src/facet/table-facet.ts +++ b/packages/s2-core/src/facet/table-facet.ts @@ -102,6 +102,13 @@ export class TableFacet extends BaseFacet { s2.on(S2Event.RANGE_FILTER, this.onFilterHandler); } + public getContentHeight(): number { + const { getTotalHeight } = this.getViewCellHeights(); + const { colsHierarchy } = this.layoutResult; + + return getTotalHeight() + colsHierarchy.height; + } + private onSortHandler = (sortParams) => { const s2 = this.spreadsheet; let params = sortParams; diff --git a/packages/s2-core/src/sheet-type/pivot-sheet.ts b/packages/s2-core/src/sheet-type/pivot-sheet.ts index b03c372382..8ce4509308 100644 --- a/packages/s2-core/src/sheet-type/pivot-sheet.ts +++ b/packages/s2-core/src/sheet-type/pivot-sheet.ts @@ -35,6 +35,10 @@ export class PivotSheet extends SpreadSheet { return realDataSet; } + public getContentHeight() { + return this.facet.getContentHeight(); + } + /** * Check if is pivot mode */