@@ -43,7 +43,7 @@ const columns = (columns, { instance }) => {
43
43
maxWidth : column . maxWidth
44
44
} ) ) ;
45
45
let availableWidth = totalWidth ;
46
- let internalDefaultColumnsCount = visibleColumns . length ;
46
+ let defaultColumnsCount = visibleColumns . length ;
47
47
const columnsWithFixedWidth = columnsWithWidthProperties
48
48
. map ( ( column ) => {
49
49
const { width, minWidth, maxWidth, accessor } = column ;
@@ -56,25 +56,45 @@ const columns = (columns, { instance }) => {
56
56
? 60
57
57
: width ;
58
58
availableWidth -= acceptedWidth ;
59
- internalDefaultColumnsCount -- ;
59
+ defaultColumnsCount -- ;
60
60
return acceptedWidth ;
61
61
}
62
- if ( minWidth > availableWidth / internalDefaultColumnsCount ) {
62
+
63
+ const columnsWithMaxWidth = columnsWithWidthProperties . filter ( ( item ) => item . maxWidth ) ;
64
+ const aggregatedColumnsMaxWidth = columnsWithMaxWidth . reduce ( ( acc , cur ) => acc + cur . maxWidth , 0 ) ;
65
+ const aggregatedColumnsMinWidth = columnsWithWidthProperties
66
+ . filter ( ( item ) => item . minWidth && ! item . maxWidth )
67
+ . reduce ( ( acc , cur ) => acc + cur . minWidth , 0 ) ;
68
+
69
+ if ( minWidth > availableWidth / defaultColumnsCount ) {
70
+ // don't apply minWidth if enough space is available because of maxWidth properties
71
+ if (
72
+ availableWidth - aggregatedColumnsMaxWidth >
73
+ aggregatedColumnsMinWidth + ( columns . length - columnsWithWidthProperties . length ) * 60
74
+ ) {
75
+ // apply minWidth only if it's larger than the calculated available width
76
+ if ( minWidth > ( availableWidth - aggregatedColumnsMaxWidth ) / columnsWithMaxWidth . length ) {
77
+ availableWidth -= minWidth ;
78
+ defaultColumnsCount -- ;
79
+ return minWidth ;
80
+ }
81
+ return false ;
82
+ }
63
83
availableWidth -= minWidth ;
64
- internalDefaultColumnsCount -- ;
84
+ defaultColumnsCount -- ;
65
85
return minWidth ;
66
86
}
67
- if ( maxWidth < availableWidth / internalDefaultColumnsCount ) {
87
+ if ( maxWidth < availableWidth / defaultColumnsCount ) {
68
88
availableWidth -= maxWidth ;
69
- internalDefaultColumnsCount -- ;
89
+ defaultColumnsCount -- ;
70
90
return maxWidth ;
71
91
}
72
92
return false ;
73
93
} )
74
94
. filter ( Boolean ) ;
75
95
76
96
const fixedWidth = columnsWithFixedWidth . reduce ( ( acc , val ) => acc + val , 0 ) ;
77
- const defaultColumnsCount = visibleColumns . length - columnsWithFixedWidth . length ;
97
+
78
98
// check if columns are visible and table has width
79
99
if ( visibleColumns . length > 0 && totalWidth > 0 ) {
80
100
// set fixedWidth as defaultWidth if all visible columns have fixed value
0 commit comments