@@ -102,6 +102,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
102
102
protected _eventPubSubService ! : EventPubSubService ;
103
103
protected _angularGridInstances : AngularGridInstance | undefined ;
104
104
protected _hideHeaderRowAfterPageLoad = false ;
105
+ protected _isAutosizeColsCalled = false ;
105
106
protected _isGridInitialized = false ;
106
107
protected _isDatasetInitialized = false ;
107
108
protected _isDatasetHierarchicalInitialized = false ;
@@ -187,7 +188,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
187
188
188
189
@Input ( )
189
190
get dataset ( ) : any [ ] {
190
- return ( this . customDataView ? this . slickGrid ?. getData ?.( ) : this . dataView ?. getItems ?. ( ) ) || [ ] ;
191
+ return ( this . customDataView ? this . slickGrid ?. getData ?.( ) : this . dataView ?. getItems ( ) ) || [ ] ;
191
192
}
192
193
set dataset ( newDataset : any [ ] ) {
193
194
const prevDatasetLn = this . _currentDatasetLength ;
@@ -205,8 +206,9 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
205
206
206
207
// expand/autofit columns on first page load
207
208
// we can assume that if the prevDataset was empty then we are on first load
208
- if ( this . gridOptions ?. autoFitColumnsOnFirstLoad && prevDatasetLn === 0 ) {
209
+ if ( this . slickGrid && this . gridOptions ?. autoFitColumnsOnFirstLoad && prevDatasetLn === 0 && ! this . _isAutosizeColsCalled ) {
209
210
this . slickGrid . autosizeColumns ( ) ;
211
+ this . _isAutosizeColsCalled = true ;
210
212
}
211
213
}
212
214
@@ -468,6 +470,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
468
470
initialization ( eventHandler : SlickEventHandler ) {
469
471
this . gridOptions . translater = this . translaterService ;
470
472
this . _eventHandler = eventHandler ;
473
+ this . _isAutosizeColsCalled = false ;
471
474
472
475
// when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
473
476
if ( this . gridOptions && ( ( this . gridOptions . frozenRow !== undefined && this . gridOptions . frozenRow >= 0 ) || this . gridOptions . frozenColumn !== undefined && this . gridOptions . frozenColumn >= 0 ) && this . gridOptions . enableMouseWheelScrollHandler === undefined ) {
@@ -755,6 +758,14 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
755
758
}
756
759
}
757
760
761
+ setData ( data : TData [ ] , shouldAutosizeColumns = false ) {
762
+ if ( shouldAutosizeColumns ) {
763
+ this . _isAutosizeColsCalled = false ;
764
+ this . _currentDatasetLength = 0 ;
765
+ }
766
+ this . dataset = data || [ ] ;
767
+ }
768
+
758
769
/**
759
770
* Check if there's any Pagination Presets defined in the Grid Options,
760
771
* if there are then load them in the paginationOptions object
@@ -1004,21 +1015,17 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
1004
1015
throw new Error ( `[Angular-Slickgrid] You cannot enable both autosize/fit viewport & resize by content, you must choose which resize technique to use. You can enable these 2 options ("autoFitColumnsOnFirstLoad" and "enableAutoSizeColumns") OR these other 2 options ("autosizeColumnsByCellContentOnFirstLoad" and "enableAutoResizeColumnsByCellContent").` ) ;
1005
1016
}
1006
1017
1007
- // expand/autofit columns on first page load
1008
- if ( grid && options . autoFitColumnsOnFirstLoad && options . enableAutoSizeColumns ) {
1009
- grid . autosizeColumns ( ) ;
1010
- }
1011
-
1012
1018
// auto-resize grid on browser resize
1013
1019
if ( options . gridHeight || options . gridWidth ) {
1014
1020
this . resizerService . resizeGrid ( 0 , { height : options . gridHeight , width : options . gridWidth } ) ;
1015
1021
} else {
1016
1022
this . resizerService . resizeGrid ( ) ;
1017
1023
}
1018
- if ( options . enableAutoResize ) {
1019
- if ( grid && options . autoFitColumnsOnFirstLoad && options . enableAutoSizeColumns ) {
1020
- grid . autosizeColumns ( ) ;
1021
- }
1024
+
1025
+ // expand/autofit columns on first page load
1026
+ if ( grid && options ?. enableAutoResize && options . autoFitColumnsOnFirstLoad && options . enableAutoSizeColumns && ! this . _isAutosizeColsCalled ) {
1027
+ grid . autosizeColumns ( ) ;
1028
+ this . _isAutosizeColsCalled = true ;
1022
1029
}
1023
1030
}
1024
1031
0 commit comments