diff --git a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts index 7aecda2f1d..8774ead68e 100644 --- a/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts +++ b/packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts @@ -554,6 +554,26 @@ describe('SpreadSheet Hidden Columns Tests', () => { expect(leafNodes.some((node) => node.id === nodeId)).toBeFalsy(); expect(leafNodes).toHaveLength(5); }); + + test.each(['grid', 'tree'])( + 'hiding the column totals should not hide the row totals for %s mode', + (hierarchyType: 'grid' | 'tree') => { + sheet.setOptions({ hierarchyType }); + sheet.render(); + const nodeId = 'root[&]总计'; + const preRowNodes = sheet.facet.layoutResult.rowNodes; + const preColumnNodes = sheet.facet.layoutResult.colNodes; + sheet.interaction.hideColumns([nodeId]); + + expect(sheet.facet.layoutResult.rowNodes[0].id).toBe(nodeId); + expect(sheet.facet.layoutResult.rowNodes.length).toBe( + preRowNodes.length, + ); + expect(sheet.facet.layoutResult.colNodes.length).toBe( + preColumnNodes.length - 1, + ); + }, + ); }); }); }); diff --git a/packages/s2-core/src/facet/layout/layout-hooks.ts b/packages/s2-core/src/facet/layout/layout-hooks.ts index 4aadb1e8f5..67b59afb61 100644 --- a/packages/s2-core/src/facet/layout/layout-hooks.ts +++ b/packages/s2-core/src/facet/layout/layout-hooks.ts @@ -43,7 +43,11 @@ export const layoutHierarchy = ( const hiddenColumnNode = facetCfg.spreadsheet?.facet?.getHiddenColumnsInfo(currentNode); - if (hiddenColumnNode) { + if ( + hiddenColumnNode && + // fix: Only hiding the column headers is supported to prevent the row subtotals from being hidden when the IDs of the row totals and column totals are the same. + facetCfg.columns.find((field) => field === currentNode.field) + ) { return false; }