fix(table): use rowHeightsMap directly in scrollToCell to fix position with dynamic row heights#5051
Merged
fangsmile merged 1 commit intoVisActor:fix/5020-scrollToRow-dynamic-row-heightfrom Mar 17, 2026
Conversation
…n with dynamic row heights getRowsHeight() has a fast path that multiplies defaultRowHeight by the row count for body rows when heightMode is 'standard', completely ignoring rowHeightsMap. This means rows with computed heights (e.g. from autoWrapText) are not reflected in the scroll position calculation, causing scrollToRow to land at the wrong position. Fix: use rowHeightsMap.getSumInRange directly in scrollToCell so that actual computed row heights are used for both the target position and the max-scroll cap. For unrendered rows, getSumInRange already falls back to getRowHeight (defaultRowHeight), so behavior is unchanged when no rows have been dynamically sized. Closes VisActor#5020
fangsmile
reviewed
Mar 16, 2026
| // This ensures dynamically-computed row heights (e.g. autoWrapText) are reflected | ||
| // in the scroll position calculation. | ||
| const top = this.rowHeightsMap.getSumInRange(0, cellAddr.row - 1); | ||
| this.scrollTop = Math.min(top - frozenHeight, this.rowHeightsMap.getSumInRange(0, this.rowCount - 1) - drawRange.height); |
Contributor
Author
There was a problem hiding this comment.
autoWrapText 走 _setRowHeight(只写 rowHeightsMap,不写 _heightResizedRowMap),所以 _heightResizedRowMap.size === 0 始终成立,fast path 始终命中,else 分支永远走不到
c972502
into
VisActor:fix/5020-scrollToRow-dynamic-row-height
2 checks passed
21 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

变更说明
scrollToRow/scrollToCell在使用动态行高(如autoWrapText: true)时,滚动位置不准确,特别是在最后一两屏时偏差明显。根因分析:
scrollToCell调用getRowsHeight(0, row-1)计算目标行的像素位置。该函数存在一个 fast path:当heightMode === 'standard'且_heightResizedRowMap.size === 0时,对 body rows 直接用defaultRowHeight × count计算,完全忽略rowHeightsMap中存储的实际行高。autoWrapText渲染时通过_setRowHeight将实际行高写入rowHeightsMap,但不会写入_heightResizedRowMap,因此 fast path 的条件始终成立,导致已计算的实际行高被忽略。结果:目标滚动位置(
top)和最大滚动上限(getAllRowsHeight() - drawHeight)均基于defaultRowHeight估算,与实际像素偏移不符。修复:在
scrollToCell中直接使用rowHeightsMap.getSumInRange计算行高偏移,绕过 fast path。对于未渲染的行,getSumInRange内部同样回落到getRowHeight(i)(defaultRowHeight),故未渲染行的行为不变。关联 Issue
Closes #5020
测试
autoWrapText: true+ 10000 条数据,调用scrollToRow(9990),确认滚动位置正确(目标行出现在视口内)autoWrapText的普通表格scrollToRow行为不变scrollToRow位置正确