import { GridOptions } from '@ag-grid-community/core' ; const gridOptions = { columnDefs : [ { field : 'country' , rowGroup : true , enableRowGroup : true } , { field : 'year' , pivot : true , enablePivot : true , pivotComparator : MyYearPivotComparator , } , { field : 'date' } , { field : 'sport' } , { field : 'gold' , aggFunc : 'sum' } , { field : 'silver' , aggFunc : 'sum' } , { field : 'bronze' , aggFunc : 'sum' } , ] , defaultColDef : { flex : 1 , minWidth : 150 , filter : true , resizable : true , } , autoGroupColumnDef : { minWidth : 250 , } , sideBar : true , pivotMode : true , suppressAggFuncInHeader : true , processSecondaryColDef : function ( colDef ) { colDef . headerName = colDef . headerName ! . toUpperCase ( ) ; } , processSecondaryColGroupDef : function ( colGroupDef ) { if ( colGroupDef . pivotKeys ! [ 0 ] === '2002' ) { colGroupDef . headerClass = 'color-background' ; } colGroupDef . headerName = 'Year ' + colGroupDef . headerName ; } , } ; function MyYearPivotComparator ( a , b ) { var requiredOrder = [ '2012' , '2010' , '2008' , '2006' , '2004' , '2002' , '2000' ] ; return requiredOrder . indexOf ( a ) - requiredOrder . indexOf ( b ) ; } 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 ) ) ; } ) ;