@@ -7,7 +7,7 @@ import ColGroup from '../ColGroup';
77import TableContext from '../context/TableContext' ;
88import type { HeaderProps } from '../Header/Header' ;
99import devRenderTimes from '../hooks/useRenderTimes' ;
10- import type { ColumnsType , ColumnType , Direction } from '../interface' ;
10+ import type { ColumnsType , ColumnType , Direction , TableLayout } from '../interface' ;
1111
1212function useColumnWidth ( colWidths : readonly number [ ] , columCount : number ) {
1313 return useMemo ( ( ) => {
@@ -36,6 +36,8 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
3636 stickyTopOffset ?: number ;
3737 stickyBottomOffset ?: number ;
3838 stickyClassName ?: string ;
39+ scrollTableStyle ?: React . CSSProperties ;
40+ tableLayout ?: TableLayout ;
3941 onScroll : ( info : { currentTarget : HTMLDivElement ; scrollLeft ?: number } ) => void ;
4042 children : ( info : HeaderProps < RecordType > ) => React . ReactNode ;
4143}
@@ -59,6 +61,8 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
5961 stickyTopOffset,
6062 stickyBottomOffset,
6163 stickyClassName,
64+ scrollTableStyle,
65+ tableLayout = 'fixed' ,
6266 onScroll,
6367 maxContentScroll,
6468 children,
@@ -115,12 +119,6 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
115119 } ;
116120 } , [ ] ) ;
117121
118- // Check if all flattenColumns has width
119- const allFlattenColumnsWithWidth = React . useMemo (
120- ( ) => flattenColumns . every ( column => column . width ) ,
121- [ flattenColumns ] ,
122- ) ;
123-
124122 // Add scrollbar column
125123 const lastColumn = flattenColumns [ flattenColumns . length - 1 ] ;
126124 const ScrollBarColumn : ColumnType < unknown > & { scrollbar : true } = {
@@ -158,6 +156,32 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
158156
159157 const mergedColumnWidth = useColumnWidth ( colWidths , columCount ) ;
160158
159+ const colGroupNode = useMemo ( ( ) => {
160+ // use original ColGroup if no data or no calculated column width, otherwise use calculated column width
161+ // Return original colGroup if no data, or mergedColumnWidth is empty, or all widths are falsy
162+ if (
163+ noData ||
164+ ! mergedColumnWidth ||
165+ mergedColumnWidth . length === 0 ||
166+ mergedColumnWidth . every ( width => ! width )
167+ ) {
168+ return ColGroup ;
169+ }
170+ return (
171+ < ColGroup
172+ colWidths = { [ ...mergedColumnWidth , combinationScrollBarSize ] }
173+ columCount = { columCount + 1 }
174+ columns = { flattenColumnsWithScrollbar }
175+ />
176+ ) ;
177+ } , [
178+ noData ,
179+ mergedColumnWidth ,
180+ combinationScrollBarSize ,
181+ columCount ,
182+ flattenColumnsWithScrollbar ,
183+ ] ) ;
184+
161185 return (
162186 < div
163187 style = { {
@@ -172,17 +196,12 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
172196 >
173197 < TableComponent
174198 style = { {
175- tableLayout : 'fixed' ,
199+ tableLayout,
176200 visibility : noData || mergedColumnWidth ? null : 'hidden' ,
201+ ...scrollTableStyle ,
177202 } }
178203 >
179- { ( ! noData || ! maxContentScroll || allFlattenColumnsWithWidth ) && (
180- < ColGroup
181- colWidths = { mergedColumnWidth ? [ ...mergedColumnWidth , combinationScrollBarSize ] : [ ] }
182- columCount = { columCount + 1 }
183- columns = { flattenColumnsWithScrollbar }
184- />
185- ) }
204+ { colGroupNode }
186205 { children ( {
187206 ...restProps ,
188207 stickyOffsets : headerStickyOffsets ,
0 commit comments