I'm rendering a kendo-grid that receives data dynamically in runtime and required to autofit the columns continuously as data arrives.
I've used autoFitColumns() on the ngAfterViewChecked lifecycle hook to keep autofitting with each new data arrival. but each autofit resets the view of the grid and the horizontal scroll is reset to the start.
I searched for other issues regarding the subjects but none worked for this scenario.
tried solutions:
- using ngZone and subscribing to OnStable
- saving the scrollLeft property of '.k-grid-content' and and assigning the value to it after the autoFitColumns() call
- calling autoFitColumns on specific changes within ngOnChanges.
without autofit there are no issues despite many dynamic data changes.
template parameters:
<kendo-grid
#grid
[kendoGridBinding]="gridData"
[skip]="skip"
[resizeable]="true"
....>
component (simplified)
export class Component {
@Input() columns$: Observable<TableColumns[]>
@Input gridData: any[];
@ViewChild(GridComponent) grid: GridComponent;
ngOnInit(){
this.columns$?.pipe(filter((cols)=> !!cols && cols.length > 0)).subscribe......
}
ngAfterViewChecked() {
this.grid?.autoFitColumns();
}Help is appreciated.