Skip to content

Commit

Permalink
fix: 修复隐藏列总计时行总计也被隐藏问题 (#2417)
Browse files Browse the repository at this point in the history
* fix: 修复隐藏列总计时行总计也被隐藏了

* fix: add fix bug comment

* fix: add test case

* fix: optimize test case

---------

Co-authored-by: wuding.why <[email protected]>
  • Loading branch information
wuhaiyang and wuding.why authored Nov 17, 2023
1 parent ed79621 commit 3b771c0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/hidden-columns-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
},
);
});
});
});
6 changes: 5 additions & 1 deletion packages/s2-core/src/facet/layout/layout-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

1 comment on commit 3b771c0

@vercel
Copy link

@vercel vercel bot commented on 3b771c0 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

antvis-s2 – ./

antvis-s2.vercel.app
antvis-s2-git-master-antvis-family.vercel.app
antvis-s2-antvis-family.vercel.app

Please sign in to comment.