---
product: "AG Grid"
title: "Row Selection API Reference"
description: "Selection API Reference for Single and Multi-Row Selection in the React Table."
framework: react
version: "36.2.0"
related:
    - title: "Single Row Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/react-data-grid/row-selection-single-row/"
    - title: "Multi-Row Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/react-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/react-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

```tsx
("use client");

import React, {
  useCallback,
  useMemo,
  useRef,
  useState,
  StrictMode,
} from "react";
import { createRoot } from "react-dom/client";
import { AgGridReact, AgGridProvider } from "ag-grid-react";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectedEvent,
  RowSelectionModule,
  RowSelectionOptions,
  SelectionChangedEvent,
  enableDevValidations,
} from "ag-grid-community";
import { IOlympicData } from "./interfaces";
import { useFetchJson } from "./useFetchJson";

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

const modules = [RowSelectionModule, ClientSideRowModelModule];

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: "100%", height: "100%" }), []);
  const gridStyle = useMemo(() => ({ height: "100%", width: "100%" }), []);

  const [columnDefs, setColumnDefs] = useState<ColDef[]>([
    { 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" },
  ]);
  const defaultColDef = useMemo<ColDef>(() => {
    return {
      flex: 1,
      minWidth: 100,
    };
  }, []);
  const rowSelection = useMemo<
    RowSelectionOptions | "single" | "multiple"
  >(() => {
    return { mode: "multiRow", headerCheckbox: false };
  }, []);

  const { data, loading } = useFetchJson<IOlympicData>(
    "https://www.ag-grid.com/example-assets/olympic-winners.json",
  );

  const onRowSelected = useCallback((event: RowSelectedEvent) => {
    console.log(
      "row " +
        event.node.data.athlete +
        " selected = " +
        event.node.isSelected(),
    );
  }, []);

  const onSelectionChanged = useCallback((event: SelectionChangedEvent) => {
    const rowCount = event.selectedNodes?.length;
    console.log("selection changed, " + rowCount + " rows selected");
  }, []);

  return (
    <AgGridProvider modules={modules}>
      <div style={containerStyle}>
        <div style={gridStyle}>
          <AgGridReact<IOlympicData>
            rowData={data}
            loading={loading}
            columnDefs={columnDefs}
            defaultColDef={defaultColDef}
            rowSelection={rowSelection}
            onRowSelected={onRowSelected}
            onSelectionChanged={onSelectionChanged}
          />
        </div>
      </div>
    </AgGridProvider>
  );
};

const root = createRoot(document.getElementById("root")!);
root.render(
  <StrictMode>
    <GridExample />
  </StrictMode>,
);
```

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

## Node Selection API

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

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

For example:

```jsx
// 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 });
```
