Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: 优化明细表滚动性能 close #2548, #2402 #2561

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 31 additions & 33 deletions packages/s2-core/src/facet/header/table-col.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,38 @@ export class TableColHeader extends ColHeader {

public frozenTrailingColGroup: IGroup;

private finalColCount: number;

private finalTrailingColCount: number;

constructor(cfg: ColHeaderConfig) {
super(cfg);
const { frozenColCount, frozenTrailingColCount } =
this.headerConfig.spreadsheet?.options;

if (frozenColCount) {
const topLevelNodes =
this.headerConfig.spreadsheet?.facet?.layoutResult.colNodes.filter(
(cell) => {
return isTopLevelNode(cell);
},
);
const { colCount, trailingColCount } = getFrozenLeafNodesCount(
topLevelNodes,
frozenColCount,
frozenTrailingColCount,
);

this.finalColCount = colCount;
this.finalTrailingColCount = trailingColCount;

if (colCount) {
this.frozenColGroup = this.addGroup({
name: KEY_GROUP_COL_FROZEN,
zIndex: FRONT_GROUND_GROUP_FROZEN_Z_INDEX,
});
}

if (frozenTrailingColCount) {
if (trailingColCount) {
this.frozenTrailingColGroup = this.addGroup({
name: KEY_GROUP_COL_FROZEN_TRAILING,
zIndex: FRONT_GROUND_GROUP_FROZEN_Z_INDEX,
Expand Down Expand Up @@ -82,24 +101,16 @@ export class TableColHeader extends ColHeader {

protected getCellGroup(node: Node) {
const { spreadsheet } = this.headerConfig;
const { frozenColCount, frozenTrailingColCount } = spreadsheet?.options;
wjgogogo marked this conversation as resolved.
Show resolved Hide resolved
const topLevelNodes = spreadsheet?.facet?.layoutResult.colNodes.filter(
(cell) => {
return isTopLevelNode(cell);
},
);
const { colCount, trailingColCount } = getFrozenLeafNodesCount(
topLevelNodes,
frozenColCount,
frozenTrailingColCount,
);
if (isFrozenCol(getLeftLeafNode(node).colIndex, colCount)) {

const leafNode = getLeftLeafNode(node).colIndex;

if (isFrozenCol(leafNode, this.finalColCount)) {
return this.frozenColGroup;
}
if (
isFrozenTrailingCol(
getLeftLeafNode(node).colIndex,
trailingColCount,
leafNode,
this.finalTrailingColCount,
spreadsheet?.facet?.layoutResult.colLeafNodes.length,
)
) {
Expand All @@ -110,25 +121,12 @@ export class TableColHeader extends ColHeader {

protected isColCellInRect(item: Node): boolean {
const { spreadsheet } = this.headerConfig;
const { frozenColCount, frozenTrailingColCount } = spreadsheet?.options;
const colLength = spreadsheet?.facet?.layoutResult.colLeafNodes.length;
const topLevelNodes = spreadsheet?.facet?.layoutResult.colNodes.filter(
(cell) => {
return isTopLevelNode(cell);
},
);
const { colCount, trailingColCount } = getFrozenLeafNodesCount(
topLevelNodes,
frozenColCount,
frozenTrailingColCount,
);

const leafNode = getLeftLeafNode(item).colIndex;
if (
isFrozenCol(getLeftLeafNode(item).colIndex, colCount) ||
isFrozenTrailingCol(
getLeftLeafNode(item).colIndex,
trailingColCount,
colLength,
)
isFrozenCol(leafNode, this.finalColCount) ||
isFrozenTrailingCol(leafNode, this.finalTrailingColCount, colLength)
) {
return true;
}
Expand Down
Loading