@@ -34,14 +34,51 @@ const columns = (columns, { instance }) => {
34
34
} ) ;
35
35
36
36
const calculateDefaultTableWidth = ( ) => {
37
- const columnsWithFixedWidth = visibleColumns . filter ( ( { width } ) => width ?? false ) . map ( ( { width } ) => width ) ;
37
+ const columnsWithWidthProperties = visibleColumns
38
+ . filter ( ( column ) => column . width ?? column . minWidth ?? column . maxWidth ?? false )
39
+ . map ( ( column ) => ( {
40
+ accessor : column . id ?? column . accessor ,
41
+ minWidth : column . minWidth ,
42
+ width : column . width ,
43
+ maxWidth : column . maxWidth
44
+ } ) ) ;
45
+ let availableWidth = totalWidth ;
46
+ let internalDefaultColumnsCount = visibleColumns . length ;
47
+ const columnsWithFixedWidth = columnsWithWidthProperties
48
+ . map ( ( column ) => {
49
+ const { width, minWidth, maxWidth, accessor } = column ;
50
+ if ( width ) {
51
+ // necessary because of default minWidth
52
+ const acceptedWidth =
53
+ accessor !== '__ui5wcr__internal_highlight_column' &&
54
+ accessor !== '__ui5wcr__internal_selection_column' &&
55
+ width < 60
56
+ ? 60
57
+ : width ;
58
+ availableWidth -= acceptedWidth ;
59
+ internalDefaultColumnsCount -- ;
60
+ return acceptedWidth ;
61
+ }
62
+ if ( minWidth > availableWidth / defaultColumnsCount ) {
63
+ availableWidth -= minWidth ;
64
+ internalDefaultColumnsCount -- ;
65
+ return minWidth ;
66
+ }
67
+ if ( maxWidth < availableWidth / defaultColumnsCount ) {
68
+ availableWidth -= maxWidth ;
69
+ internalDefaultColumnsCount -- ;
70
+ return maxWidth ;
71
+ }
72
+ return false ;
73
+ } )
74
+ . filter ( Boolean ) ;
75
+
38
76
const fixedWidth = columnsWithFixedWidth . reduce ( ( acc , val ) => acc + val , 0 ) ;
39
77
40
78
const defaultColumnsCount = visibleColumns . length - columnsWithFixedWidth . length ;
41
-
42
79
// check if columns are visible and table has width
43
80
if ( visibleColumns . length > 0 && totalWidth > 0 ) {
44
- // set fixedWidth as defaultWidth if visible columns have fixed value
81
+ // set fixedWidth as defaultWidth if all visible columns have fixed value
45
82
if ( visibleColumns . length === columnsWithFixedWidth . length ) {
46
83
return fixedWidth / visibleColumns . length ;
47
84
}
0 commit comments