---
product: "AG Grid"
title: "Row Selection API Reference"
description: "Selection API Reference for Single and Multi-Row Selection in the JavaScript Table."
framework: javascript
version: "36.2.0"
related:
    - title: "Single Row Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/row-selection-single-row/"
    - title: "Multi-Row Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/row-selection-multi-row/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Row Selection API Reference

Selection API Reference for Single and Multi-Row Selection

> **Note**
>
> The row selection state can be saved and restored as part of [Grid State](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/grid-state/).

## Configuration API

### Single Row Mode

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `mode` | `'singleRow'` |  |  |  |
| `enableClickSelection` | `boolean \| 'enableDeselection' \| 'enableSelection'` |  |  |  |
| `checkboxes` | `boolean \| CheckboxSelectionCallback` |  |  |  |
| `checkboxLocation` | `CheckboxLocation` |  |  |  |
| `hideDisabledCheckboxes` | `boolean` |  |  |  |
| `isRowSelectable` | `IsRowSelectable` |  |  |  |
| `copySelectedRows` | `boolean` |  |  |  |
| `enableSelectionWithoutKeys` | `boolean` |  |  |  |
| `masterSelects` | `'self' \| 'detail'` |  |  |  |

### Multi-Row Mode

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `mode` | `'multiRow'` |  |  |  |
| `groupSelects` | `GroupSelectionMode` |  |  |  |
| `selectAll` | `SelectAllMode` |  |  |  |
| `headerCheckbox` | `boolean` |  |  |  |
| `ctrlASelectsRows` | `boolean` |  |  |  |
| `enableClickSelection` | `boolean \| 'enableDeselection' \| 'enableSelection'` |  |  |  |
| `checkboxes` | `boolean \| CheckboxSelectionCallback` |  |  |  |
| `checkboxLocation` | `CheckboxLocation` |  |  |  |
| `hideDisabledCheckboxes` | `boolean` |  |  |  |
| `isRowSelectable` | `IsRowSelectable` |  |  |  |
| `copySelectedRows` | `boolean` |  |  |  |
| `enableSelectionWithoutKeys` | `boolean` |  |  |  |
| `masterSelects` | `'self' \| 'detail'` |  |  |  |

## Selection Events

There are two events with regards to selection, illustrated in the example below:

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `rowSelected` | `RowSelectedEvent` |  |  |  |
| `selectionChanged` | `SelectionChangedEvent` |  |  |  |

The example below has configured messages to be logged to the developer console on both these events firing. Click a row while the developer console is open to see an illustration of the events.

#### Selection Events

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectedEvent,
  RowSelectionModule,
  SelectionChangedEvent,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([RowSelectionModule, ClientSideRowModelModule]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 150 },
    { field: "age", maxWidth: 90 },
    { field: "country", minWidth: 150 },
    { field: "year", maxWidth: 90 },
    { field: "date", minWidth: 150 },
    { field: "sport", minWidth: 150 },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
    { field: "total" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: { mode: "multiRow", headerCheckbox: false },
  onRowSelected,
  onSelectionChanged,
};

function onRowSelected(event: RowSelectedEvent) {
  console.log(
    "row " + event.node.data.athlete + " selected = " + event.node.isSelected(),
  );
}

function onSelectionChanged(event: SelectionChangedEvent) {
  const rowCount = event.selectedNodes?.length;

  console.log("selection changed, " + rowCount + " rows selected");
}

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((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));
```

[Live example: Selection Events](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-api-reference/selection-events/typescript/)

## Node Selection API

To select rows programmatically, use the `node.setSelected(params)` method.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `setSelected` | `Function` |  |  |  |
| `isSelected` | `Function` |  |  |  |

For example:

```js
// set selected, keep any other selections
node.setSelected(true);

// set selected, exclusively, remove any other selections
node.setSelected(true, true);

// un-select
node.setSelected(false);

// check status of node selection
const selected = node.isSelected();
```

## Grid Selection API

The grid API has the following methods for selection:

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectAll` | `Function` |  |  |  |
| `deselectAll` | `Function` |  |  |  |
| `getSelectedNodes` | `Function` |  |  |  |
| `getSelectedRows` | `Function` |  |  |  |
| `setNodesSelected` | `Function` |  |  |  |

If you want to select only the filtered rows, you could do this using the following:

```js
// loop through each node after filter
const nodes = [];
api.forEachNodeAfterFilter(node => {
    nodes.push(node);
});
api.setNodesSelected({ nodes, newValue: true });
```
