@@ -7,7 +7,7 @@ import ColGroup from '../ColGroup';
7
7
import TableContext from '../context/TableContext' ;
8
8
import type { HeaderProps } from '../Header/Header' ;
9
9
import devRenderTimes from '../hooks/useRenderTimes' ;
10
- import type { ColumnsType , ColumnType , Direction } from '../interface' ;
10
+ import type { ColumnsType , ColumnType , Direction , TableLayout } from '../interface' ;
11
11
12
12
function useColumnWidth ( colWidths : readonly number [ ] , columCount : number ) {
13
13
return useMemo ( ( ) => {
@@ -36,6 +36,8 @@ export interface FixedHeaderProps<RecordType> extends HeaderProps<RecordType> {
36
36
stickyTopOffset ?: number ;
37
37
stickyBottomOffset ?: number ;
38
38
stickyClassName ?: string ;
39
+ scrollTableStyle ?: React . CSSProperties ;
40
+ tableLayout ?: TableLayout ;
39
41
onScroll : ( info : { currentTarget : HTMLDivElement ; scrollLeft ?: number } ) => void ;
40
42
children : ( info : HeaderProps < RecordType > ) => React . ReactNode ;
41
43
}
@@ -59,6 +61,8 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
59
61
stickyTopOffset,
60
62
stickyBottomOffset,
61
63
stickyClassName,
64
+ scrollTableStyle,
65
+ tableLayout = 'fixed' ,
62
66
onScroll,
63
67
maxContentScroll,
64
68
children,
@@ -115,12 +119,6 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
115
119
} ;
116
120
} , [ ] ) ;
117
121
118
- // Check if all flattenColumns has width
119
- const allFlattenColumnsWithWidth = React . useMemo (
120
- ( ) => flattenColumns . every ( column => column . width ) ,
121
- [ flattenColumns ] ,
122
- ) ;
123
-
124
122
// Add scrollbar column
125
123
const lastColumn = flattenColumns [ flattenColumns . length - 1 ] ;
126
124
const ScrollBarColumn : ColumnType < unknown > & { scrollbar : true } = {
@@ -158,6 +156,32 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
158
156
159
157
const mergedColumnWidth = useColumnWidth ( colWidths , columCount ) ;
160
158
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
+
161
185
return (
162
186
< div
163
187
style = { {
@@ -172,17 +196,12 @@ const FixedHolder = React.forwardRef<HTMLDivElement, FixedHeaderProps<any>>((pro
172
196
>
173
197
< TableComponent
174
198
style = { {
175
- tableLayout : 'fixed' ,
199
+ tableLayout,
176
200
visibility : noData || mergedColumnWidth ? null : 'hidden' ,
201
+ ...scrollTableStyle ,
177
202
} }
178
203
>
179
- { ( ! noData || ! maxContentScroll || allFlattenColumnsWithWidth ) && (
180
- < ColGroup
181
- colWidths = { mergedColumnWidth ? [ ...mergedColumnWidth , combinationScrollBarSize ] : [ ] }
182
- columCount = { columCount + 1 }
183
- columns = { flattenColumnsWithScrollbar }
184
- />
185
- ) }
204
+ { colGroupNode }
186
205
{ children ( {
187
206
...restProps ,
188
207
stickyOffsets : headerStickyOffsets ,
0 commit comments