Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
4 changes: 3 additions & 1 deletion docs/examples/measureRowRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const data = [
{ key: 3, name: 'Jime', age: 35 },
];

// 自定义 MeasureRow 渲染,隐藏弹层内容
// 注意,这个 measureRow 实际上是一个 <tr> 标签
// 按照 html 规范,tr 的父元素必须是 table、thead、tbody、tfoot 标签,子元素必须是 th、td 标签
// 因此这里我们用一个 div 包裹是不对的,在控制台中会报错
const measureRowRender: TableProps['measureRowRender'] = measureRow => (
<div style={{ display: 'none' }}>{measureRow}</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成 tr 避免 warning

Copy link
Member Author

@li-jia-nan li-jia-nan Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不行,加什么都会报错,原本的 dom 结构就是刚刚好,我直接用 cloneElement 把 style 传进去了

);
Expand Down
31 changes: 11 additions & 20 deletions src/FixedHolder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,31 +157,16 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro

const mergedColumnWidth = useColumnWidth(colWidths, columCount);

const colGroupNode = useMemo(() => {
const mayBeEmpty = useMemo<boolean>(() => {
// use original ColGroup if no data or no calculated column width, otherwise use calculated column width
// Return original colGroup if no data, or mergedColumnWidth is empty, or all widths are falsy
if (
return (
noData ||
!mergedColumnWidth ||
mergedColumnWidth.length === 0 ||
!mergedColumnWidth.length ||
mergedColumnWidth.every(width => !width)
) {
return ColGroup;
Copy link
Member Author

@li-jia-nan li-jia-nan Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ColGroup 是一个函数,直接渲染到 UI 会报错,这里应该返回 null

}
return (
<ColGroup
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
columCount={columCount + 1}
columns={flattenColumnsWithScrollbar}
/>
);
}, [
noData,
mergedColumnWidth,
combinationScrollBarSize,
columCount,
flattenColumnsWithScrollbar,
]);
}, [noData, mergedColumnWidth]);

return (
<div
Expand All @@ -203,7 +188,13 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
width: scrollX,
}}
>
{colGroupNode}
{mayBeEmpty ? null : (
<ColGroup
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
columCount={columCount + 1}
columns={flattenColumnsWithScrollbar}
/>
)}
{children({
...restProps,
stickyOffsets: headerStickyOffsets,
Expand Down