---
title: "Load Retry"
enterprise: true
framework: javascript
version: "36.1.0"
---

# Load Retry

When a datasource load fails, call `retryServerSideLoads()` to reload the failed rows at a later time.

When loading fails, the datasource informs the grid of such using the `fail()` callback instead of using the `success()` callback. Calling `fail()` puts the loading rows into a Loading Failed state which hides the loading spinner. No data is shown in these rows as they are not loaded.

Failed loads can be retried by using the grid API `retryServerSideLoads()`. This will retry all loads that have previously failed.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `retryServerSideLoads` | `Function` |  |  | Gets all failed server side loads to retry. Module: [`ServerSideRowModelApiModule`](https://www.ag-grid.com/javascript-data-grid/modules/). |

### Examples

The following example demonstrates load retrying. Note the following:

- When the checkbox 'Make Loads Fail' is checked, all subsequent loads will fail, i.e. the Datasource will call `fail()` instead of `success()`. Try checking the checkbox and expand a few groups to observe failed loading.
- When the button 'Retry Failed Loads' is pressed, any loads which were marked as failed are retried.
- When the button 'Reset Entire Grid' is pressed, the grid will reset. This allows you to have 'Make Loads Fail' checked while starting from scratch, thus failing loading of the top level of rows.

#### Load Retry

```ts
import {
  GridApi,
  GridOptions,
  IServerSideDatasource,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  RowGroupingModule,
  ServerSideRowModelApiModule,
  ServerSideRowModelModule,
} from "ag-grid-enterprise";
import { FakeServer } from "./fakeServer";
import { IOlympicData } from "./interfaces";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([
  RowGroupingModule,
  ServerSideRowModelModule,
  ServerSideRowModelApiModule,
]);

let gridApi: GridApi<IOlympicData>;
const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    {
      // demonstrating the use of valueGetters
      colId: "country",
      valueGetter: "data.country",
      rowGroup: true,
      hide: true,
    },
    { field: "sport", rowGroup: true, hide: true },
    { field: "year", minWidth: 100 },
    { field: "gold", aggFunc: "sum" },
    { field: "silver", aggFunc: "sum" },
    { field: "bronze", aggFunc: "sum" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 120,
  },
  autoGroupColumnDef: {
    flex: 1,
    minWidth: 280,
    field: "athlete",
  },

  // use the server-side row model
  rowModelType: "serverSide",
  maxConcurrentDatasourceRequests: 1,

  suppressAggFuncInHeader: true,
  purgeClosedRowNodes: true,

  cacheBlockSize: 20,
};

function getServerSideDatasource(server: any): IServerSideDatasource {
  return {
    getRows: (params) => {
      console.log("[Datasource] - rows requested by grid: ", params.request);

      const response = server.getData(params.request);

      // adding delay to simulate real server call
      setTimeout(() => {
        if (response.success) {
          // call the success callback
          params.success({
            rowData: response.rows,
            rowCount: response.lastRow,
          });
        } else {
          // inform the grid request failed
          params.fail();
        }
      }, 1000);
    },
  };
}

function onBtRetry() {
  gridApi!.retryServerSideLoads();
}

function onBtReset() {
  gridApi!.refreshServerSide({ purge: true });
}

const gridDiv = document.querySelector<HTMLElement>("#myGrid")!;
gridApi = createGrid(gridDiv, gridOptions);

fetch("https://www.ag-grid.com/example-assets/olympic-winners.json")
  .then((response) => response.json())
  .then(function (data) {
    // setup the fake server with entire dataset
    const fakeServer = new FakeServer(data);

    // create datasource with a reference to the fake server
    const datasource = getServerSideDatasource(fakeServer);

    // register the datasource with the grid
    gridApi!.setGridOption("serverSideDatasource", datasource);
  });

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).onBtRetry = onBtRetry;
  (<any>window).onBtReset = onBtReset;
}
```

[Live example: Load Retry](https://www.ag-grid.com/examples/server-side-model-retry/retry-infinite/typescript/)
