Skip to content

fix: table onCell-method cause offset in width calculation#1315

Open
cactuser-Lu wants to merge 6 commits intoreact-component:masterfrom
cactuser-Lu:fix-colspan-offset
Open

fix: table onCell-method cause offset in width calculation#1315
cactuser-Lu wants to merge 6 commits intoreact-component:masterfrom
cactuser-Lu:fix-colspan-offset

Conversation

@cactuser-Lu
Copy link
Contributor

@cactuser-Lu cactuser-Lu commented Aug 25, 2025

fix: ant-design/ant-design#54860
对于以下代码,当0、1列为固定列,且使用 onCell 进行表格列合并时,存在一个问题:

//第0列
onCell: (_, index) => ({
  colSpan: index === 1 ?0 : 1,
}),
//第1列
onCell: (_, index) => ({
  colSpan: index === 1 ?2 : 1,
}),
  1. 当 columnIndex: 0 的单元格因为 colSpan 返回 0 而不被渲染时,浏览器会顺延地让 columnIndex: 1 且 colspan="2" 的 占据第 0 列和第 1 列的空间。所以 的宽度是 width[0] + width[1],这是符合预期的。
  2. 偏移不正确:useStickyOffsets在计算固定列的 left 偏移时,没有排除掉那些因 colSpan 返回 0 而在视觉上被“隐藏”的列,导致偏移量计算错误,这里的left计算为width[0] ,而实际应该为0,出现重叠或错位。

为此,我在bodyrow中动态去除了 colSpan=0列的宽度,修正了相关方法

Summary by CodeRabbit

  • 新功能

    • 表格按行“粘性偏移”增强:按行动态计算固定列偏移,按需跳过 colSpan=0 列,并使用预计算的单元格属性缓存以提升渲染稳定性。
  • 修复

    • 解决 colSpan=0 导致的固定列错位与遮挡问题,滚动与定位更稳定,兼容可展开行场景。
  • 变更

    • 行级信息包含列宽;粘性相关接口接受可选行上下文与缓存参数以支持按行计算。
  • 测试

    • 新增回归测试,覆盖固定列、合并单元格及可展开行交互。

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

table组件使用colspan对固定列设置合并时单元格偏移错误

4 participants