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 , } , } , getDetailRowData : function ( params ) { params . successCallback ( params . data . callRecords ) ; } , template : function ( params ) { var personName = params . data . name ; return ( '<div style="height: 100%; background-color: #EDF6FF; padding: 20px; box-sizing: border-box;">' + '  <div style="height: 10%; padding: 2px; font-weight: bold;">###### Name: ' + personName + '</div>' + '  <div ref="eDetailGrid" style="height: 90%;"></div>' + '</div>' ) ; } , } as IDetailCellRendererParams , 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-data.json' ) . then ( response => response . json ( ) ) . then ( function ( data ) { gridOptions . api ! . setRowData ( data ) ; } ) ; } ) ;