import { GetServerSideStoreParamsParams , GridOptions , IServerSideDatasource , ServerSideStoreParams } from '@ag-grid-community/core' ; declare var FakeServer ; const gridOptions = { columnDefs : [ { field : 'country' , enableRowGroup : true , rowGroup : true } , { field : 'sport' , enableRowGroup : true , rowGroup : true } , { field : 'year' , minWidth : 100 } , { field : 'gold' , aggFunc : 'sum' } , { field : 'silver' , aggFunc : 'sum' } , { field : 'bronze' , aggFunc : 'sum' } , ] , defaultColDef : { flex : 1 , minWidth : 120 , resizable : true , sortable : true , } , rowGroupPanelShow : 'always' , autoGroupColumnDef : { flex : 1 , minWidth : 280 , } , cacheBlockSize : 4 , rowModelType : 'serverSide' , serverSideStoreType : 'partial' , getServerSideStoreParams : function ( params ) { var noGroupingActive = params . rowGroupColumns . length == 0 ; var res ; if ( noGroupingActive ) { res = { storeType : 'partial' , cacheBlockSize : 100 , maxBlocksInCache : 2 , } ; } else { var topLevelRows = params . level == 0 ; res = { storeType : topLevelRows ? 'full' : 'partial' , cacheBlockSize : params . level == 1 ? 5 : 2 , maxBlocksInCache : - 1 , } ; } console . log ( '############## NEW STORE ##############' ) ; console . log ( 'getServerSideStoreParams, level = ' + params . level + ', result = ' + JSON . stringify ( res ) ) ; return res ; } , suppressAggFuncInHeader : true , animateRows : true , } ; function getServerSideDatasource ( server ) { return { getRows : function ( params ) { console . log ( '[Datasource] - rows requested by grid: ' , params . request ) ; var response = server . getData ( params . request ) ; setTimeout ( function ( ) { if ( response . success ) { params . success ( { rowData : response . rows , rowCount : response . lastRow } ) ; } else { params . fail ( ) ; } } , 400 ) ; } , } ; } 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 ( function ( data ) { var fakeServer = new FakeServer ( data ) ; var datasource = getServerSideDatasource ( fakeServer ) ; gridOptions . api ! . setServerSideDatasource ( datasource ) ; } ) ; } ) ;