@@ -102,6 +102,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
102102 protected _eventPubSubService ! : EventPubSubService ;
103103 protected _angularGridInstances : AngularGridInstance | undefined ;
104104 protected _hideHeaderRowAfterPageLoad = false ;
105+ protected _isAutosizeColsCalled = false ;
105106 protected _isGridInitialized = false ;
106107 protected _isDatasetInitialized = false ;
107108 protected _isDatasetHierarchicalInitialized = false ;
@@ -187,7 +188,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
187188
188189 @Input ( )
189190 get dataset ( ) : any [ ] {
190- return ( this . customDataView ? this . slickGrid ?. getData ?.( ) : this . dataView ?. getItems ?. ( ) ) || [ ] ;
191+ return ( this . customDataView ? this . slickGrid ?. getData ?.( ) : this . dataView ?. getItems ( ) ) || [ ] ;
191192 }
192193 set dataset ( newDataset : any [ ] ) {
193194 const prevDatasetLn = this . _currentDatasetLength ;
@@ -205,8 +206,9 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
205206
206207 // expand/autofit columns on first page load
207208 // 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 ) {
209210 this . slickGrid . autosizeColumns ( ) ;
211+ this . _isAutosizeColsCalled = true ;
210212 }
211213 }
212214
@@ -468,6 +470,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
468470 initialization ( eventHandler : SlickEventHandler ) {
469471 this . gridOptions . translater = this . translaterService ;
470472 this . _eventHandler = eventHandler ;
473+ this . _isAutosizeColsCalled = false ;
471474
472475 // when detecting a frozen grid, we'll automatically enable the mousewheel scroll handler so that we can scroll from both left/right frozen containers
473476 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
755758 }
756759 }
757760
761+ setData ( data : TData [ ] , shouldAutosizeColumns = false ) {
762+ if ( shouldAutosizeColumns ) {
763+ this . _isAutosizeColsCalled = false ;
764+ this . _currentDatasetLength = 0 ;
765+ }
766+ this . dataset = data || [ ] ;
767+ }
768+
758769 /**
759770 * Check if there's any Pagination Presets defined in the Grid Options,
760771 * if there are then load them in the paginationOptions object
@@ -1004,21 +1015,17 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
10041015 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").` ) ;
10051016 }
10061017
1007- // expand/autofit columns on first page load
1008- if ( grid && options . autoFitColumnsOnFirstLoad && options . enableAutoSizeColumns ) {
1009- grid . autosizeColumns ( ) ;
1010- }
1011-
10121018 // auto-resize grid on browser resize
10131019 if ( options . gridHeight || options . gridWidth ) {
10141020 this . resizerService . resizeGrid ( 0 , { height : options . gridHeight , width : options . gridWidth } ) ;
10151021 } else {
10161022 this . resizerService . resizeGrid ( ) ;
10171023 }
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 ;
10221029 }
10231030 }
10241031
0 commit comments