diff --git a/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts b/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts index c0de4f2fb4..246d6fbdf6 100644 --- a/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts +++ b/packages/s2-core/__tests__/unit/sheet-type/pivot-sheet-spec.ts @@ -706,7 +706,7 @@ describe('PivotSheet Tests', () => { const clearDrillDownDataSpy = jest .spyOn(s2.dataSet, 'clearDrillDownData' as any) - .mockImplementation(() => {}); + .mockImplementation(() => true); s2.clearDrillDownData(); @@ -722,6 +722,20 @@ describe('PivotSheet Tests', () => { renderSpy.mockRestore(); }); + test(`shouldn't rerender without drill down data`, () => { + const renderSpy = jest.spyOn(s2, 'render').mockImplementationOnce(() => {}); + + const clearDrillDownDataSpy = jest + .spyOn(s2.dataSet, 'clearDrillDownData' as any) + .mockImplementation(() => false); + + s2.clearDrillDownData(); + + expect(clearDrillDownDataSpy).toHaveBeenCalledTimes(1); + // rerender + expect(renderSpy).toHaveBeenCalledTimes(0); + }); + test('should get extra field text', () => { const pivotSheet = new PivotSheet( container, diff --git a/packages/s2-core/src/data-set/pivot-data-set.ts b/packages/s2-core/src/data-set/pivot-data-set.ts index db31d0af28..99dd3975c6 100644 --- a/packages/s2-core/src/data-set/pivot-data-set.ts +++ b/packages/s2-core/src/data-set/pivot-data-set.ts @@ -171,7 +171,7 @@ export class PivotDataSet extends BaseDataSet { const store = this.spreadsheet.store; const idPathMap = store.get('drillDownIdPathMap'); if (!idPathMap) { - return; + return false; } const drillDownDataCache = store.get( 'drillDownDataCache', @@ -225,6 +225,7 @@ export class PivotDataSet extends BaseDataSet { } store.set('drillDownIdPathMap', idPathMap); + return true; } /** diff --git a/packages/s2-core/src/sheet-type/pivot-sheet.ts b/packages/s2-core/src/sheet-type/pivot-sheet.ts index a8bea5c20a..56d7e5db44 100644 --- a/packages/s2-core/src/sheet-type/pivot-sheet.ts +++ b/packages/s2-core/src/sheet-type/pivot-sheet.ts @@ -89,8 +89,8 @@ export class PivotSheet extends SpreadSheet { public clearDrillDownData(rowNodeId?: string, preventRender?: boolean) { if (this.dataSet instanceof PivotDataSet) { - this.dataSet.clearDrillDownData(rowNodeId); - if (!preventRender) { + const cleaned = this.dataSet.clearDrillDownData(rowNodeId); + if (cleaned && !preventRender) { // 重置当前交互 this.interaction.reset(); this.render(false);