@@ -34,14 +34,51 @@ const columns = (columns, { instance }) => {
3434 } ) ;
3535
3636 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+
3876 const fixedWidth = columnsWithFixedWidth . reduce ( ( acc , val ) => acc + val , 0 ) ;
3977
4078 const defaultColumnsCount = visibleColumns . length - columnsWithFixedWidth . length ;
41-
4279 // check if columns are visible and table has width
4380 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
4582 if ( visibleColumns . length === columnsWithFixedWidth . length ) {
4683 return fixedWidth / visibleColumns . length ;
4784 }
0 commit comments