Skip to content

Commit

Permalink
fix: 明细表未指定 dataCfg.fields 配置时不应该渲染空数据占位 (#3003)
Browse files Browse the repository at this point in the history
* fix: 明细表未指定 dataCfg.fields 配置时不渲染空数据占位

* fix: 优化写法
  • Loading branch information
lijinke666 authored Nov 29, 2024
1 parent b8fdd2a commit 60d6497
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
25 changes: 25 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/table-sheet-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,5 +429,30 @@ describe('TableSheet normal spec', () => {

await expectEmptyPlaceholder(s2);
});

test('should not render empty placeholder if all fields is empty', async () => {
const s2 = new TableSheet(
getContainer(),
{ ...dataCfg, fields: {}, data: [] },
{
...options,
frozen: {},
seriesNumber: {
enable: false,
},
},
);

await s2.render();
const [rect, icon, text] = (s2.facet as TableFacet).emptyPlaceholderGroup
.children;

expect(
(s2.facet as TableFacet).emptyPlaceholderGroup.children,
).toHaveLength(0);
expect(rect).not.toBeDefined();
expect(icon).not.toBeDefined();
expect(text).not.toBeDefined();
});
});
});
9 changes: 5 additions & 4 deletions packages/s2-core/src/facet/base-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ export abstract class BaseFacet {
this.init();
}

protected shouldRender() {
return !areAllFieldsEmpty(this.spreadsheet.dataCfg.fields);
}

public getLayoutResult = (): LayoutResult => {
return {
...this.layoutResult,
Expand Down Expand Up @@ -609,11 +613,8 @@ export abstract class BaseFacet {
this.emitPaginationEvent();
};

/**
* Start render, call from outside
*/
public render() {
if (areAllFieldsEmpty(this.spreadsheet.dataCfg.fields)) {
if (!this.shouldRender()) {
return;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/s2-core/src/facet/frozen-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ export abstract class FrozenFacet extends BaseFacet {
}

public render() {
if (!this.shouldRender()) {
return;
}

this.calculateFrozenGroupInfo();
this.renderFrozenPanelCornerGroup();
super.render();
Expand Down
4 changes: 4 additions & 0 deletions packages/s2-core/src/facet/table-facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class TableFacet extends FrozenFacet {
}

public render() {
if (!this.shouldRender()) {
return;
}

super.render();
this.renderEmptyPlaceholder();
}
Expand Down

0 comments on commit 60d6497

Please sign in to comment.