---
title: "Active Overlay"
framework: javascript
version: "36.1.0"
---

# Active Overlay

Applications can display an overlay on demand regardless of grid state. This is achieved by providing an active overlay which can be one of the provided overlays or be a custom overlay component.

#### Active Overlay (Component Class)

```ts
import {
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { CustomOverlay, CustomParams } from "./customOverlay";

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

ModuleRegistry.registerModules([ClientSideRowModelModule]);

interface IAthlete {
  athlete: string;
  country: string;
}

const columnDefs: ColDef[] = [
  { field: "athlete", flex: 1 },
  { field: "country", flex: 1 },
];

const rowData: IAthlete[] = [
  { athlete: "Michael Phelps", country: "United States" },
  { athlete: "Natalie Coughlin", country: "United States" },
  { athlete: "Aleksey Nemov", country: "Russia" },
  { athlete: "Alicia Coutts", country: "Australia" },
];

let gridApi: GridApi<IAthlete>;

const activeOverlayParams: CustomParams = {
  count: 1,
};

const gridOptions: GridOptions<IAthlete> = {
  columnDefs,
  rowData,
  activeOverlay: CustomOverlay,
  activeOverlayParams,
};

function showActiveOverlay() {
  gridApi.setGridOption("activeOverlay", CustomOverlay);
}

function clearActiveOverlay() {
  gridApi.setGridOption("activeOverlay", undefined);
}
function incParam() {
  activeOverlayParams.count++;
  gridApi.setGridOption("activeOverlayParams", activeOverlayParams);
}

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

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

[Live example: Active Overlay (Component Class)](https://www.ag-grid.com/examples/overlays-active/active-overlay-component/typescript/)

## Display an Active Overlay

To display an overlay on demand set the `activeOverlay` / `activeOverlayParams` grid option. To clear the overlay set `activeOverlay = undefined`.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `activeOverlay` | `any` |  |  | Display an overlay on demand. If provided takes precedence over the grid provided overlays. - name of a provided overlay, i.e `agLoadingOverlay`, `agNoRowsOverlay`, `agNoMatchingRowsOverlay`, `agExportingOverlay` - component class/function. - key of a custom component registered in the `components` map. - `undefined` to clear. |
| `activeOverlayParams` | `any` |  |  | Custom parameters to be supplied to the `activeOverlay` component in addition to `IOverlayParams`. Updating the params will trigger a refresh of the active overlay. |

Implement the `IOverlayComp` interface to provide a custom overlay the grid will supply `IOverlayParams` whenever the component is created or refreshed.

```ts

interface IOverlayComp&lt;TData = any, TContext = any, TParams extends Readonly<<span/>IOverlayParams<<span/>TData, TContext>> = IOverlayParams<<span/>TData, TContext>&gt; {
  // Return the DOM element of your component, this is what the grid puts into the DOM 
  getGui(): <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement" target="_blank" rel="noreferrer">HTMLElement</a>;

  // Gets called once by grid when the component is being removed; if your component needs to do any cleanup, do it here 
  destroy?(): void;

  // The init(params) method is called on the component once. 
  init?(params: TParams): AgPromise<<span/>void>  |  void;

  // Gets called when the `overlayComponentParams` grid option is updated
  refresh?(params: TParams): void;

}
```

The example below demonstrates using the grid provided overlays as an active overlay. Note the following:

- activeOverlays take precedence over the provided loading overlay.
- activeOverlay can be displayed no matter what the grid state, i.e showing the no-rows overlay even when there are rows.
- StatusOverlay is registered in the [components](https://www.ag-grid.com/javascript-data-grid/components/#2-by-name) map and shown by setting `activateOverlay = "statusOverlay"` to the key used.

#### Active Overlay Switcher

```ts
import {
  ClientSideRowModelModule,
  ColDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { StatusOverlay } from "./statusOverlay";

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

ModuleRegistry.registerModules([ClientSideRowModelModule]);

interface IAthlete {
  athlete: string;
  country: string;
}

const columnDefs: ColDef<IAthlete>[] = [
  { field: "athlete", flex: 1 },
  { field: "country", flex: 1 },
];

const rowData: IAthlete[] = [
  { athlete: "Michael Phelps", country: "United States" },
  { athlete: "Alicia Coutts", country: "Australia" },
];

let gridApi: GridApi<IAthlete>;
let statusOverlayCounter = 0;

const gridOptions: GridOptions<IAthlete> = {
  columnDefs,
  rowData,
  components: {
    statusOverlay: StatusOverlay,
  },
};

function showNoRowsOverlay() {
  gridApi.updateGridOptions({
    activeOverlay: "agNoRowsOverlay",
    activeOverlayParams: undefined,
  });
}

function showStatusOverlay() {
  gridApi.updateGridOptions({
    activeOverlay: "statusOverlay",
    activeOverlayParams: {
      myCounter: ++statusOverlayCounter,
    },
  });
}

function hideOverlay() {
  gridApi.updateGridOptions({
    activeOverlay: undefined,
    activeOverlayParams: undefined,
  });
}

function setLoading(isChecked: boolean) {
  gridApi.updateGridOptions({
    loading: isChecked ? true : undefined,
  });
}

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

const loadingToggle =
  document.querySelector<HTMLInputElement>("#loading-toggle");
if (loadingToggle) {
  loadingToggle.addEventListener("change", () =>
    setLoading(loadingToggle.checked),
  );
  setLoading(loadingToggle.checked);
}

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

[Live example: Active Overlay Switcher](https://www.ag-grid.com/examples/overlays-active/active-overlay-switcher/typescript/)
