@@ -21,9 +21,9 @@ type TableLayoutOptions<T> = ListLayoutOptions<T> & {
21
21
getDefaultWidth : ( props ) => string | number ,
22
22
columnWidths : Map < Key , number > ,
23
23
getColumnWidth : ( key : Key ) => number ,
24
- setColumnWidth : ( key : Key , width : number ) => void ,
24
+ setColumnWidth : ( column : any , width : number ) => void ,
25
25
hasResizedColumn : ( key : Key ) => boolean ,
26
- currentResizeColumn : Key ,
26
+ currentResizeColumn : any ,
27
27
resizeDelta : number
28
28
}
29
29
@@ -35,9 +35,9 @@ export class TableLayout<T> extends ListLayout<T> {
35
35
stickyColumnIndices : number [ ] ;
36
36
getDefaultWidth : ( props ) => string | number ;
37
37
getColumnWidth_ : ( key : Key ) => number ;
38
- setColumnWidth : ( key : Key , width : number ) => void ;
38
+ setColumnWidth_ : ( column : any , width : number ) => void ;
39
39
hasResizedColumn : ( key : Key ) => boolean ;
40
- currentResizeColumn : Key ;
40
+ currentResizeColumn : any ;
41
41
resizeDelta : number ;
42
42
wasLoading = false ;
43
43
isLoading = false ;
@@ -47,7 +47,7 @@ export class TableLayout<T> extends ListLayout<T> {
47
47
this . getDefaultWidth = options . getDefaultWidth ;
48
48
this . columnWidths = options . columnWidths ;
49
49
this . getColumnWidth_ = options . getColumnWidth ;
50
- this . setColumnWidth = options . setColumnWidth ;
50
+ this . setColumnWidth_ = options . setColumnWidth ;
51
51
this . hasResizedColumn = options . hasResizedColumn ;
52
52
this . currentResizeColumn = options . currentResizeColumn ;
53
53
this . columnWidthsRef = this . columnWidths ;
@@ -71,11 +71,26 @@ export class TableLayout<T> extends ListLayout<T> {
71
71
this . wasLoading = this . isLoading ;
72
72
this . isLoading = loadingState === 'loading' || loadingState === 'loadingMore' ;
73
73
74
- const resizeIndex = this . collection . columns . findIndex ( column => column . key === this . currentResizeColumn ) ;
75
- let affectedResizeColumns = this . collection . columns . slice ( resizeIndex + 1 , this . collection . columns . length ) ;
76
- let remainingSpace = this . virtualizer . visibleRect . width ;
77
- remainingSpace = this . collection . columns . slice ( 0 , resizeIndex + 1 ) . reduce ( ( acc , column ) => acc - this . getColumnWidth_ ( column . key ) , this . virtualizer . visibleRect . width ) ;
74
+ // only rebuild columns that come after the column being resized, if no column is being resized, they will all be built
75
+ const resizeIndex = this . collection . columns . findIndex ( column => column . key === this . currentResizeColumn ?. key ) ;
76
+ // if resizing, set the column width for the resized column to the delta bounded by it's min/max
77
+ if ( resizeIndex > - 1 ) {
78
+ const columnProps = this . collection . columns [ resizeIndex ] . props ;
79
+ const boundedResizeDelta = Math . max ( this . getMinWidth ( columnProps ?. minWidth ) , Math . min ( this . getMaxWidth ( columnProps . maxWidth ) , this . resizeDelta ) ) ;
80
+
81
+ if ( columnProps . width ) {
82
+ // Controlled component - explicit width is defined and should always win.
83
+ // Unsure: Set column width to current width but call onResize with the new width?
84
+ this . setColumnWidth_ ( this . currentResizeColumn , columnProps . width ) ;
85
+ columnProps . onResize && columnProps . onResize ( boundedResizeDelta ) ;
86
+ } else {
87
+ this . setColumnWidth ( this . currentResizeColumn , boundedResizeDelta ) ;
88
+ }
89
+ }
90
+ const affectedResizeColumns = this . collection . columns . slice ( resizeIndex + 1 , this . collection . columns . length ) ;
91
+ const remainingSpace = this . collection . columns . slice ( 0 , resizeIndex + 1 ) . reduce ( ( acc , column ) => acc - this . getColumnWidth_ ( column . key ) , this . virtualizer . visibleRect . width ) ;
78
92
this . buildColumnWidths ( affectedResizeColumns , remainingSpace ) ;
93
+
79
94
let header = this . buildHeader ( ) ;
80
95
let body = this . buildBody ( 0 ) ;
81
96
body . layoutInfo . rect . width = Math . max ( header . layoutInfo . rect . width , body . layoutInfo . rect . width ) ;
@@ -86,6 +101,11 @@ export class TableLayout<T> extends ListLayout<T> {
86
101
] ;
87
102
}
88
103
104
+ setColumnWidth ( column , newWidth ) {
105
+ this . setColumnWidth_ ( column , newWidth ) ;
106
+ column . props . onResize && column . props . onResize ( newWidth ) ;
107
+ }
108
+
89
109
buildColumnWidths ( affectedResizeColumns : GridNode < T > [ ] , remainingSpace : number ) {
90
110
this . stickyColumnIndices = [ ] ;
91
111
@@ -104,7 +124,7 @@ export class TableLayout<T> extends ListLayout<T> {
104
124
if ( this . getIsStatic ( width ) ) {
105
125
let w = this . parseWidth ( width ) ;
106
126
this . columnWidthsRef . set ( column . key , w ) ;
107
- this . setColumnWidth ( column . key , w ) ;
127
+ this . setColumnWidth ( column , w ) ;
108
128
remainingSpace -= w ;
109
129
} else {
110
130
remainingColumns . add ( column ) ;
@@ -126,7 +146,7 @@ export class TableLayout<T> extends ListLayout<T> {
126
146
let i = 0 ;
127
147
for ( let column of remainingColumns ) {
128
148
this . columnWidthsRef . set ( column . key , remCols [ i ] . columnWidth ) ;
129
- this . setColumnWidth ( column . key , remCols [ i ] . columnWidth ) ;
149
+ this . setColumnWidth ( column , remCols [ i ] . columnWidth ) ;
130
150
i ++ ;
131
151
}
132
152
}
0 commit comments