import { FirstDataRenderedEvent , GridOptions , IDetailCellRendererParams } from '@ag-grid-community/core' ; const gridOptions = { columnDefs : [ { field : 'name' , cellRenderer : 'agGroupCellRenderer' } , { field : 'account' } , { field : 'calls' } , { field : 'minutes' , valueFormatter : "x.toLocaleString() + 'm'" } , ] , defaultColDef : { flex : 1 , } , masterDetail : true , detailCellRendererParams : { detailGridOptions : { columnDefs : [ { field : 'callId' } , { field : 'direction' } , { field : 'number' } , { field : 'duration' , valueFormatter : "x.toLocaleString() + 's'" } , { field : 'switchCode' } , ] , defaultColDef : { flex : 1 , } , onGridReady : function ( params ) { params . api . setDomLayout ( 'autoHeight' ) ; } , } , getDetailRowData : function ( params ) { params . successCallback ( params . data . callRecords ) ; } , } as IDetailCellRendererParams , getRowHeight : function ( params ) { if ( params . node && params . node . detail ) { var offset = 80 ; var allDetailRowHeight = params . data . callRecords . length * params . api . getSizesForCurrentTheme ( ) . rowHeight ; var gridSizes = params . api . getSizesForCurrentTheme ( ) ; return allDetailRowHeight + ( gridSizes && gridSizes . headerHeight || 0 ) + offset ; } } , onFirstDataRendered : onFirstDataRendered , } ; function onFirstDataRendered ( params ) { setTimeout ( function ( ) { params . api . getDisplayedRowAtIndex ( 1 ) ! . setExpanded ( true ) ; } , 0 ) ; } document . addEventListener ( 'DOMContentLoaded' , function ( ) { var gridDiv = document . querySelector ( '#myGrid' ) ; new agGrid . Grid ( gridDiv , gridOptions ) ; fetch ( 'https://www.ag-grid.com/example-assets/master-detail-dynamic-row-height-data.json' ) . then ( response => response . json ( ) ) . then ( function ( data ) { gridOptions . api ! . setRowData ( data ) ; } ) ; } ) ;