@@ -8,8 +8,6 @@ import { IgxColumnComponent } from '../columns/column.component';
8
8
@Injectable ( )
9
9
export class IgxColumnResizingService {
10
10
11
- private pinnedMaxWidth : string ;
12
-
13
11
/**
14
12
* @hidden
15
13
*/
@@ -57,18 +55,29 @@ export class IgxColumnResizingService {
57
55
*/
58
56
get restrictResizeMin ( ) : number {
59
57
const actualMinWidth = parseFloat ( this . column . minWidth ) ;
60
- const minWidth = actualMinWidth < parseFloat ( this . column . width ) ? actualMinWidth : parseFloat ( this . column . width ) ;
58
+ const actualWidth = this . column . headerCell . elementRef . nativeElement . getBoundingClientRect ( ) . width ;
59
+ const gridAvailableSize = this . column . grid . calcWidth - this . column . grid . featureColumnsWidth ( ) ;
60
+ const isMinPercentageWidth = this . column . minWidth && typeof this . column . minWidth === 'string' &&
61
+ this . column . minWidth . indexOf ( '%' ) !== - 1 ;
62
+ const calcMinWidth = isMinPercentageWidth ? actualMinWidth / 100 * gridAvailableSize : actualMinWidth ;
63
+ const minWidth = calcMinWidth < actualWidth ? calcMinWidth : actualWidth ;
61
64
62
- return this . column . headerCell . elementRef . nativeElement . getBoundingClientRect ( ) . width - minWidth ;
65
+ return actualWidth - minWidth ;
63
66
}
64
67
65
68
/**
66
69
* Returns the maximal possible width to which the column can be resized.
67
70
*/
68
71
get restrictResizeMax ( ) : number {
69
72
const actualWidth = this . column . headerCell . elementRef . nativeElement . getBoundingClientRect ( ) . width ;
73
+ const gridAvailableSize = this . column . grid . calcWidth - this . column . grid . featureColumnsWidth ( ) ;
74
+ const isMaxPercentageWidth = this . column . maxWidth && typeof this . column . maxWidth === 'string' &&
75
+ this . column . maxWidth . indexOf ( '%' ) !== - 1 ;
76
+ const calcMaxWidth = isMaxPercentageWidth ?
77
+ parseFloat ( this . column . maxWidth ) / 100 * gridAvailableSize :
78
+ parseFloat ( this . column . maxWidth ) ;
70
79
if ( this . column . maxWidth ) {
71
- return parseFloat ( this . column . maxWidth ) - actualWidth ;
80
+ return calcMaxWidth - actualWidth ;
72
81
} else {
73
82
return Number . MAX_SAFE_INTEGER ;
74
83
}
@@ -109,12 +118,44 @@ export class IgxColumnResizingService {
109
118
this . showResizer = false ;
110
119
const diff = event . clientX - this . startResizePos ;
111
120
112
- let currentColWidth = parseFloat ( this . column . width ) ;
121
+ const colWidth = this . column . width ;
122
+ const isPercentageWidth = colWidth && typeof colWidth === 'string' && colWidth . indexOf ( '%' ) !== - 1 ;
123
+ let currentColWidth = parseFloat ( colWidth ) ;
124
+ const actualWidth = this . column . headerCell . elementRef . nativeElement . getBoundingClientRect ( ) . width ;
125
+ currentColWidth = Number . isNaN ( currentColWidth ) ? actualWidth : currentColWidth + 'px' ;
126
+
127
+ if ( isPercentageWidth ) {
128
+ this . _handlePercentageResize ( diff , this . column ) ;
129
+ } else {
130
+ this . _handlePixelResize ( diff , this . column ) ;
131
+ }
132
+
133
+
134
+ this . zone . run ( ( ) => { } ) ;
135
+
136
+ if ( currentColWidth !== parseFloat ( this . column . width ) ) {
137
+ this . column . grid . onColumnResized . emit ( {
138
+ column : this . column ,
139
+ prevWidth : isPercentageWidth ? currentColWidth + '%' : currentColWidth + 'px' ,
140
+ newWidth : this . column . width
141
+ } ) ;
142
+ }
143
+
144
+ this . isColumnResizing = false ;
145
+ }
146
+
147
+ protected _handlePixelResize ( diff : number , column : IgxColumnComponent ) {
148
+ let currentColWidth = parseFloat ( column . width ) ;
149
+ const gridAvailableSize = column . grid . calcWidth - column . grid . featureColumnsWidth ( ) ;
113
150
const actualWidth = this . column . headerCell . elementRef . nativeElement . getBoundingClientRect ( ) . width ;
114
151
currentColWidth = Number . isNaN ( currentColWidth ) || ( currentColWidth < actualWidth ) ? actualWidth : currentColWidth ;
115
152
116
- const colMinWidth = this . getColMinWidth ( this . column ) ;
117
- const colMaxWidth = this . getColMaxWidth ( this . column ) ;
153
+ const isMinPercentageWidth = column . minWidth && typeof column . minWidth === 'string' && column . minWidth . indexOf ( '%' ) !== - 1 ;
154
+ const isMaxPercentageWidth = column . maxWidth && typeof column . maxWidth === 'string' && column . maxWidth . indexOf ( '%' ) !== - 1 ;
155
+ const colMinWidth = ! isMinPercentageWidth ? this . getColMinWidth ( this . column ) :
156
+ parseFloat ( this . column . minWidth ) / 100 * gridAvailableSize ;
157
+ const colMaxWidth = ! isMaxPercentageWidth ? parseFloat ( column . maxWidth ) :
158
+ parseFloat ( this . column . maxWidth ) / 100 * gridAvailableSize ;
118
159
if ( this . column . grid . hasColumnLayouts ) {
119
160
this . resizeColumnLayoutFor ( this . column , diff ) ;
120
161
} else {
@@ -126,18 +167,25 @@ export class IgxColumnResizingService {
126
167
this . column . width = ( currentColWidth + diff ) + 'px' ;
127
168
}
128
169
}
170
+ }
129
171
130
- this . zone . run ( ( ) => { } ) ;
172
+ protected _handlePercentageResize ( diff : number , column : IgxColumnComponent ) {
173
+ const currentPercentWidth = parseFloat ( column . width ) ;
174
+ const gridAvailableSize = column . grid . calcWidth - column . grid . featureColumnsWidth ( ) ;
131
175
132
- if ( currentColWidth !== parseFloat ( this . column . width ) ) {
133
- this . column . grid . onColumnResized . emit ( {
134
- column : this . column ,
135
- prevWidth : currentColWidth . toString ( ) ,
136
- newWidth : this . column . width
137
- } ) ;
138
- }
176
+ const diffPercentage = ( diff / gridAvailableSize ) * 100 ;
177
+ const isMinPercentageWidth = column . minWidth && typeof column . minWidth === 'string' && column . minWidth . indexOf ( '%' ) !== - 1 ;
178
+ const isMaxPercentageWidth = column . maxWidth && typeof column . maxWidth === 'string' && column . maxWidth . indexOf ( '%' ) !== - 1 ;
179
+ const colMinWidth = isMinPercentageWidth ? parseFloat ( column . minWidth ) : parseFloat ( column . minWidth ) / gridAvailableSize * 100 ;
180
+ const colMaxWidth = isMaxPercentageWidth ? parseFloat ( column . maxWidth ) : parseFloat ( column . maxWidth ) / gridAvailableSize * 100 ;
139
181
140
- this . isColumnResizing = false ;
182
+ if ( currentPercentWidth + diffPercentage < colMinWidth ) {
183
+ this . column . width = colMinWidth + '%' ;
184
+ } else if ( colMaxWidth && ( currentPercentWidth + diffPercentage > colMaxWidth ) ) {
185
+ this . column . width = colMaxWidth + '%' ;
186
+ } else {
187
+ this . column . width = ( currentPercentWidth + diffPercentage ) + '%' ;
188
+ }
141
189
}
142
190
143
191
protected getColMinWidth ( column : IgxColumnComponent ) {
@@ -149,10 +197,6 @@ export class IgxColumnResizingService {
149
197
return actualMinWidth < currentColWidth ? actualMinWidth : currentColWidth ;
150
198
}
151
199
152
- protected getColMaxWidth ( column : IgxColumnComponent ) {
153
- return column . pinned ? parseFloat ( this . pinnedMaxWidth ) : parseFloat ( column . maxWidth ) ;
154
- }
155
-
156
200
protected resizeColumnLayoutFor ( column : IgxColumnComponent , diff : number ) {
157
201
const relativeColumns = column . getResizableColUnderEnd ( ) ;
158
202
const combinedSpan = relativeColumns . reduce ( ( acc , col ) => acc + col . spanUsed , 0 ) ;
@@ -174,7 +218,7 @@ export class IgxColumnResizingService {
174
218
const resizeScaled = ( diff / updatedCombinedSpan ) * col . target . gridColumnSpan ;
175
219
176
220
const minWidth = this . getColMinWidth ( col . target ) ;
177
- const maxWidth = this . getColMaxWidth ( col . target ) ;
221
+ const maxWidth = parseFloat ( col . target . maxWidth ) ;
178
222
if ( currentResizeWidth + resizeScaled < minWidth ) {
179
223
col . target . width = minWidth + 'px' ;
180
224
updatedDiff += ( currentResizeWidth - minWidth ) ;
0 commit comments