import { ColGroupDef , GridOptions , IColumnToolPanel , } from '@ag-grid-community/core' ; const columnDefs = [ { groupId : 'athleteGroupId' , headerName : 'Athlete' , children : [ { headerName : 'Name' , field : 'athlete' , minWidth : 200 , filter : 'agTextColumnFilter' , } , { groupId : 'competitionGroupId' , headerName : 'Competition' , children : [ { field : 'year' } , { field : 'date' , minWidth : 180 } ] , } , ] , } , { groupId : 'medalsGroupId' , headerName : 'Medals' , children : [ { field : 'gold' } , { field : 'silver' } , { field : 'bronze' } , { field : 'total' } , ] , } , ] ; const gridOptions = { columnDefs : columnDefs , defaultColDef : { flex : 1 , minWidth : 100 , enableValue : true , enableRowGroup : true , enablePivot : true , filter : true , sortable : true , resizable : true , } , sideBar : 'columns' , onGridReady : function ( params ) { var columnToolPanel = ( gridOptions . api ! . getToolPanelInstance ( 'columns' ) as unknown ) as IColumnToolPanel ; columnToolPanel . collapseColumnGroups ( ) ; } , } ; function expandAllGroups ( ) { var columnToolPanel = ( gridOptions . api ! . getToolPanelInstance ( 'columns' ) as unknown ) as IColumnToolPanel ; columnToolPanel . expandColumnGroups ( ) ; } function collapseAllGroups ( ) { var columnToolPanel = ( gridOptions . api ! . getToolPanelInstance ( 'columns' ) as unknown ) as IColumnToolPanel ; columnToolPanel . collapseColumnGroups ( ) ; } function expandAthleteAndCompetitionGroups ( ) { var columnToolPanel = ( gridOptions . api ! . getToolPanelInstance ( 'columns' ) as unknown ) as IColumnToolPanel ; columnToolPanel . expandColumnGroups ( [ 'athleteGroupId' , 'competitionGroupId' ] ) ; } function collapseCompetitionGroups ( ) { var columnToolPanel = ( gridOptions . api ! . getToolPanelInstance ( 'columns' ) as unknown ) as IColumnToolPanel ; columnToolPanel . collapseColumnGroups ( [ 'competitionGroupId' ] ) ; } document . addEventListener ( 'DOMContentLoaded' , function ( ) { var gridDiv = document . querySelector ( '#myGrid' ) ; new agGrid . Grid ( gridDiv , gridOptions ) ; fetch ( 'https://www.ag-grid.com/example-assets/olympic-winners.json' ) . then ( response => response . json ( ) ) . then ( data => gridOptions . api ! . setRowData ( data ) ) ; } ) ;