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 */