Skip to content

Commit

Permalink
perf: 优化明细表滚动性能 close #2548, #2402 (#2561)
Browse files Browse the repository at this point in the history
perf: 优化明细表滚动性能
  • Loading branch information
wjgogogo authored and lijinke666 committed Mar 4, 2024
1 parent b027feb commit c2d5812
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions packages/s2-core/src/facet/header/table-col.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export class TableColHeader extends ColHeader {

public frozenTrailingColGroup: Group;

private finalColCount: number;

private finalTrailingColCount: number;

private topLevelColNodeLength: number;

constructor(config: ColHeaderConfig) {
super(config);
this.initFrozenColGroups();
Expand Down Expand Up @@ -59,7 +65,18 @@ export class TableColHeader extends ColHeader {
trailingColCount: frozenTrailingColCount,
} = headerConfig.spreadsheet.options.frozen!;

if (frozenColCount) {
const topLevelNodes = headerConfig.spreadsheet.facet.getColNodes(0);
const { colCount, trailingColCount } = getFrozenLeafNodesCount(
topLevelNodes,
frozenColCount!,
frozenTrailingColCount!,
);

this.finalColCount = colCount;
this.finalTrailingColCount = trailingColCount;
this.topLevelColNodeLength = topLevelNodes.length;

if (colCount) {
this.frozenColGroup = this.appendChild(
new Group({
name: KEY_GROUP_COL_FROZEN,
Expand All @@ -68,7 +85,7 @@ export class TableColHeader extends ColHeader {
);
}

if (frozenTrailingColCount) {
if (trailingColCount) {
this.frozenTrailingColGroup = this.appendChild(
new Group({
name: KEY_GROUP_COL_FROZEN_TRAILING,
Expand All @@ -80,6 +97,7 @@ export class TableColHeader extends ColHeader {

public clear() {
super.clear();

this.frozenTrailingColGroup?.removeChildren();
this.frozenColGroup?.removeChildren();

Expand All @@ -94,16 +112,13 @@ export class TableColHeader extends ColHeader {
}

private getColFrozenOptionsByNode(node: Node) {
const { spreadsheet } = this.getHeaderConfig();
const { colCount = 0, trailingColCount = 0 } = spreadsheet.options.frozen!;

const leftLeafNode = getLeftLeafNode(node);
const topLevelNodes = spreadsheet.facet.getColNodes(0);

return {
colLength: topLevelNodes.length,
colLength: this.topLevelColNodeLength,
leftLeafNodeColIndex: leftLeafNode.colIndex,
...getFrozenLeafNodesCount(topLevelNodes, colCount, trailingColCount),
colCount: this.finalColCount,
trailingColCount: this.finalTrailingColCount,
};
}

Expand Down

0 comments on commit c2d5812

Please sign in to comment.