11let grids = [ ] ;
2- const minWidth = 100 ;
32
43export function init ( gridElement , autoFocus ) {
54 if ( gridElement === undefined || gridElement === null ) {
@@ -220,11 +219,13 @@ export function enableColumnResizing(gridElement, resizeColumnOnAllRows = true)
220219 }
221220
222221 const id = gridElement . id ;
223- grids . push ( {
224- id,
225- columns,
226- initialWidths,
227- } ) ;
222+ if ( ! grids . find ( grid => grid . id === id ) ) {
223+ grids . push ( {
224+ id,
225+ columns,
226+ initialWidths,
227+ } ) ;
228+ }
228229
229230 function setListeners ( div , isRTL ) {
230231 let pageX , curCol , curColWidth ;
@@ -255,7 +256,7 @@ export function enableColumnResizing(gridElement, resizeColumnOnAllRows = true)
255256 const diffX = isRTL ? pageX - e . pageX : e . pageX - pageX ;
256257 const column = columns . find ( ( { header } ) => header === curCol ) ;
257258
258- column . size = parseInt ( Math . max ( minWidth , curColWidth + diffX ) , 10 ) + 'px' ;
259+ column . size = parseInt ( Math . max ( parseInt ( column . header . style . minWidth ) , curColWidth + diffX ) , 10 ) + 'px' ;
259260
260261 columns . forEach ( ( col ) => {
261262 if ( col . size . startsWith ( 'minmax' ) ) {
@@ -352,7 +353,7 @@ export function resetColumnWidths(gridElement) {
352353}
353354
354355export function resizeColumnDiscrete ( gridElement , column , change ) {
355-
356+ const isGrid = gridElement . classList . contains ( 'grid' ) ;
356357 const columns = [ ] ;
357358 let headerBeingResized ;
358359
@@ -370,27 +371,32 @@ export function resizeColumnDiscrete(gridElement, column, change) {
370371
371372 grids . find ( ( { id } ) => id === gridElement . id ) . columns . forEach ( column => {
372373 if ( column . header === headerBeingResized ) {
373- const width = headerBeingResized . getBoundingClientRect ( ) . width + change ;
374+ const width = headerBeingResized . offsetWidth + change ; //. getBoundingClientRect().width + change;
374375
375376 if ( change < 0 ) {
376- column . size = Math . max ( minWidth , width ) + 'px' ;
377+ column . size = Math . max ( parseInt ( column . header . style . minWidth ) , width ) + 'px' ;
377378 }
378379 else {
379380 column . size = width + 'px' ;
380381 }
382+ column . header . style . width = column . size ;
381383 }
382- else {
384+ if ( isGrid ) {
385+ // for grid we need to recalculate all columns that are minmax
383386 if ( column . size . startsWith ( 'minmax' ) ) {
384387 column . size = parseInt ( column . header . clientWidth , 10 ) + 'px' ;
385388 }
389+ columns . push ( column . size ) ;
386390 }
387- columns . push ( column . size ) ;
388391 } ) ;
389392
390- gridElement . style . gridTemplateColumns = columns . join ( ' ' ) ;
393+ if ( isGrid ) {
394+ gridElement . style . gridTemplateColumns = columns . join ( ' ' ) ;
395+ }
391396}
392397
393398export function resizeColumnExact ( gridElement , column , width ) {
399+ const isGrid = gridElement . classList . contains ( 'grid' ) ;
394400 const columns = [ ] ;
395401 let headerBeingResized = gridElement . querySelector ( '.column-header[col-index="' + column + '"]' ) ;
396402
@@ -400,17 +406,22 @@ export function resizeColumnExact(gridElement, column, width) {
400406
401407 grids . find ( ( { id } ) => id === gridElement . id ) . columns . forEach ( column => {
402408 if ( column . header === headerBeingResized ) {
403- column . size = Math . max ( minWidth , width ) + 'px' ;
409+ column . size = Math . max ( parseInt ( column . header . style . minWidth ) , width ) + 'px' ;
410+ column . header . style . width = column . size ;
404411 }
405- else {
412+ if ( isGrid ) {
413+ // for grid we need to recalculate all columns that are minmax
406414 if ( column . size . startsWith ( 'minmax' ) ) {
407415 column . size = parseInt ( column . header . clientWidth , 10 ) + 'px' ;
408416 }
417+ column . header . style . width = column . size ;
418+ columns . push ( column . size ) ;
409419 }
410- columns . push ( column . size ) ;
411420 } ) ;
412421
413- gridElement . style . gridTemplateColumns = columns . join ( ' ' ) ;
422+ if ( isGrid ) {
423+ gridElement . style . gridTemplateColumns = columns . join ( ' ' ) ;
424+ }
414425
415426 gridElement . dispatchEvent ( new CustomEvent ( 'closecolumnresize' , { bubbles : true } ) ) ;
416427 gridElement . focus ( ) ;
0 commit comments