@@ -16,6 +16,26 @@ import CopyButton from '../advancedSearch/CopyButton';
16
16
import type { Theme } from '@mui/material/styles' ;
17
17
import type { TableType } from './Types' ;
18
18
19
+ /**
20
+ * Enhanced Table Component
21
+ *
22
+ * Usage example with spacer column:
23
+ * <AttuGrid
24
+ * colDefinitions={[
25
+ * { id: 'name', label: 'Name', disablePadding: false },
26
+ * { id: 'age', label: 'Age', disablePadding: false }
27
+ * ]}
28
+ * addSpacerColumn={true} // This will add a spacer column that absorbs remaining space
29
+ * // ... other props
30
+ * />
31
+ *
32
+ * The spacer column will:
33
+ * - Have width: 'auto' and minWidth: 'auto'
34
+ * - Display no content
35
+ * - Naturally absorb remaining horizontal space without forcing table width
36
+ * - Prevent unnecessary horizontal scrollbars
37
+ */
38
+
19
39
const EnhancedTable : FC < TableType > = props => {
20
40
let {
21
41
selected,
@@ -44,10 +64,30 @@ const EnhancedTable: FC<TableType> = props => {
44
64
orderBy,
45
65
rowDecorator = ( ) => ( { } ) ,
46
66
rowHeight,
67
+ // whether to add a spacer column to control space distribution
68
+ addSpacerColumn = false ,
47
69
} = props ;
48
70
49
71
const hasData = rows && rows . length > 0 ;
50
72
73
+ // Add spacer column definition if needed
74
+ const finalColDefinitions = addSpacerColumn
75
+ ? [
76
+ ...colDefinitions ,
77
+ {
78
+ id : '__spacer__' ,
79
+ align : 'left' as const ,
80
+ disablePadding : false ,
81
+ label : '' ,
82
+ getStyle : ( ) => ( {
83
+ width : '66.7%' ,
84
+ minWidth : 'auto' ,
85
+ } ) ,
86
+ formatter : ( ) => null ,
87
+ } ,
88
+ ]
89
+ : colDefinitions ;
90
+
51
91
return (
52
92
< TableContainer
53
93
sx = { theme => ( {
@@ -70,7 +110,7 @@ const EnhancedTable: FC<TableType> = props => {
70
110
>
71
111
{ ! headEditable ? (
72
112
< EnhancedTableHead
73
- colDefinitions = { colDefinitions }
113
+ colDefinitions = { finalColDefinitions }
74
114
numSelected = { selected . length }
75
115
order = { order }
76
116
orderBy = { orderBy }
@@ -144,12 +184,30 @@ const EnhancedTable: FC<TableType> = props => {
144
184
</ TableCell >
145
185
) }
146
186
147
- { colDefinitions . map ( ( colDef , i ) => {
187
+ { finalColDefinitions . map ( ( colDef , i ) => {
148
188
const { actionBarConfigs = [ ] , needCopy = false } =
149
189
colDef ;
150
190
const cellStyleFromDef = colDef . getStyle
151
191
? colDef . getStyle ( row [ colDef . id ] )
152
192
: { } ;
193
+
194
+ // Skip rendering for spacer column
195
+ if ( colDef . id === '__spacer__' ) {
196
+ return (
197
+ < TableCell
198
+ key = { colDef . id }
199
+ sx = { [
200
+ ( theme : Theme ) => ( {
201
+ borderBottom : `1px solid ${ theme . palette . divider } ` ,
202
+ } ) ,
203
+ cellStyleFromDef ,
204
+ ] }
205
+ >
206
+ { /* Empty content for spacer column */ }
207
+ </ TableCell >
208
+ ) ;
209
+ }
210
+
153
211
return colDef . showActionCell ? (
154
212
< TableCell
155
213
sx = {
@@ -323,8 +381,8 @@ const EnhancedTable: FC<TableType> = props => {
323
381
} ) }
324
382
colSpan = {
325
383
openCheckBox
326
- ? colDefinitions . length + 1
327
- : colDefinitions . length
384
+ ? finalColDefinitions . length + 1
385
+ : finalColDefinitions . length
328
386
}
329
387
>
330
388
{ noData }
@@ -344,8 +402,8 @@ const EnhancedTable: FC<TableType> = props => {
344
402
} ) }
345
403
colSpan = {
346
404
openCheckBox
347
- ? colDefinitions . length + 1
348
- : colDefinitions . length
405
+ ? finalColDefinitions . length + 1
406
+ : finalColDefinitions . length
349
407
}
350
408
>
351
409
< LoadingTable />
0 commit comments