Skip to content

Commit

Permalink
perf(Table): improve lock column table scroll performance, close #4058 (
Browse files Browse the repository at this point in the history
#4254)

Co-authored-by: 林俊 <[email protected]>
  • Loading branch information
jun599 and 林俊 authored Feb 23, 2023
1 parent 5f8d6e8 commit 45ae326
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/table/fixed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,25 @@ export default function fixed(BaseComponent, stickyLock) {
const leftFunc = scrollToRightEnd ? 'removeClass' : 'addClass';
dom[leftFunc](table, `${prefix}table-scrolling-to-right`);
}
if (current.currentTarget !== current.target) {
return;
}
if (currentTarget === bodyNode) {
if (headerNode && scrollLeft !== headerNode.scrollLeft) {
headerNode.scrollLeft = scrollLeft;
}
} else if (currentTarget === headerNode) {
if (bodyNode && scrollLeft !== bodyNode.scrollLeft) {
bodyNode.scrollLeft = scrollLeft;

// 通过定时器避免重复设置表格的左滚动距离
if (!this.scrollTarget || this.scrollTarget === currentTarget) {
this.scrollTarget = currentTarget;
window.clearTimeout(this.timeoutId);

this.timeoutId = window.setTimeout(() => {
this.scrollTarget = null;
this.timeoutId = undefined;
}, 100);

if (currentTarget === bodyNode) {
if (headerNode && scrollLeft !== headerNode.scrollLeft) {
headerNode.scrollLeft = scrollLeft;
}
} else if (currentTarget === headerNode) {
if (bodyNode && scrollLeft !== bodyNode.scrollLeft) {
bodyNode.scrollLeft = scrollLeft;
}
}
}
};
Expand Down

0 comments on commit 45ae326

Please sign in to comment.