I solved this problem using ngStyle and window.innerHeight:
HTML:
<div style="padding:10px 10px 0px 10px; ">
<div style="font-size: x-large; font-weight: bold;
border: 2px solid black;border-radius: 5px;
padding: 10px 10px 10px 10px; margin-bottom: 15px;
">
ag-grid domLayout autoheight work-around for scrolling
<div>
<!-- there is no scroll bar when using domLayout autoHeight -->
<!--
<ag-grid-angular style="width: 100%;"
domLayout='autoHeight'
class="ag-theme-balham"
[rowData]="rowData"
[columnDefs]="columnDefs">
</ag-grid-angular>
-->
<!-- but you can use ngStyle and window.innerHeight instead -->
<ag-grid-angular style="width: 100%;"
[ngStyle]=gridStyle
class="ag-theme-balham"
[rowData]="rowData"
[columnDefs]="columnDefs">
</ag-grid-angular>
</div>
</div>
Angular:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
title = 'ag-grid domLayout autoheight work-around for scrolling ';
columnDefs = [
{headerName: 'Row', field: 'row' }
];
rowData: any[] = [];
gridStyle:any;
ngOnInit() {
// set the height dynamically to the current window height
let windowHeight:string = window.innerHeight + 'px';
this.gridStyle = {'height': windowHeight};
for (let row = 1; row <= 100; row++) {
this.rowData.push({'row': 'Row: ' + row });
}
}
}