Skip to content

Commit 46a165d

Browse files
fix: column header not align before column width being calculated (#1332)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 5531b2a commit 46a165d

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/FixedHolder/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
137137

138138
const mergedColumnWidth = useColumnWidth(colWidths, columCount);
139139

140+
const colGroupNode = useMemo(() => {
141+
// use original ColGroup if no data or no calculated column width, otherwise use calculated column width
142+
if (noData || !mergedColumnWidth) {
143+
return colGroup;
144+
}
145+
return (
146+
<ColGroup
147+
colWidths={[...mergedColumnWidth, combinationScrollBarSize]}
148+
columCount={columCount + 1}
149+
columns={flattenColumnsWithScrollbar}
150+
/>
151+
);
152+
}, [noData, mergedColumnWidth, colGroup, combinationScrollBarSize, columCount, flattenColumnsWithScrollbar]);
153+
140154
return (
141155
<div
142156
style={{
@@ -155,16 +169,7 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
155169
...scrollTableStyle,
156170
}}
157171
>
158-
{/* use original ColGroup if no data, otherwise use calculated column width */}
159-
{noData ? (
160-
colGroup
161-
) : (
162-
<ColGroup
163-
colWidths={mergedColumnWidth ? [...mergedColumnWidth, combinationScrollBarSize] : []}
164-
columCount={columCount + 1}
165-
columns={flattenColumnsWithScrollbar}
166-
/>
167-
)}
172+
{colGroupNode}
168173
{children({
169174
...restProps,
170175
stickyOffsets: headerStickyOffsets,

0 commit comments

Comments
 (0)