---
product: "AG Grid"
title: "Single Row Selection"
description: "Configure single row selection, with and without checkboxes"
framework: javascript
version: "36.2.0"
related:
    - title: "Multi-Row Selection"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/row-selection-multi-row/"
    - title: "API Reference"
      url: "https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/row-selection-api-reference/"
llms: "https://www.ag-grid.com/archive/36.2.0/llms.txt"
---

# Single Row Selection

Enable users to select a single row within a grid.

## Enabling Single Row Selection

To enable single row selection set `rowSelection.mode` to `'singleRow'`.

```js
const gridOptions = {
    rowSelection: {
        mode: 'singleRow'
    },

    // other grid options ...
}
```

The example below uses this configuration to restrict selection to a single row

#### Enabling Row Selection

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  GridStateModule,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([
  RowSelectionModule,
  GridStateModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 150 },
    { field: "age", maxWidth: 90 },
    { field: "year", maxWidth: 90 },
    { field: "sport", minWidth: 150 },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: { mode: "singleRow" },
  initialState: {
    rowSelection: ["2"],
  },
};

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

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi.setGridOption("rowData", data));
```

[Live example: Enabling Row Selection](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-single-row/enabling-row-selection/typescript/)

Deselect a row by clicking its checkbox. Alternatively, you can do this via the keyboard by focusing the row and pressing the `␣ Space` key.

## Removing Selection Checkboxes

To prevent any row selection checkboxes from being rendered, set `rowSelection.checkboxes` to `false`. You will also need to enable click selection by setting `enableClickSelection: true`.

```js
const gridOptions = {
    rowSelection: {
        mode: 'singleRow',
        checkboxes: false,
        enableClickSelection: true,
    },

    // other grid options ...
}
```

#### Disabling Checkboxes

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  GridStateModule,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([
  RowSelectionModule,
  GridStateModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete", minWidth: 150 },
    { field: "age", maxWidth: 90 },
    { field: "year", maxWidth: 90 },
    { field: "sport", minWidth: 150 },
    { field: "gold" },
    { field: "silver" },
    { field: "bronze" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: {
    mode: "singleRow",
    checkboxes: false,
    enableClickSelection: true,
  },
  initialState: {
    rowSelection: ["2"],
  },
};

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

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi.setGridOption("rowData", data));
```

[Live example: Disabling Checkboxes](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-single-row/removing-selection-checkboxes/typescript/)

> **Note**
>
> Setting `rowSelection.checkboxes` to the boolean `false` removes the checkboxes entirely. Passing a function instead keeps the checkboxes present and enables or disables them per row: a selectable row for which the function returns `false` shows a disabled checkbox rather than removing it.
>
> For rows where both `isRowSelectable` and `rowSelection.checkboxes` return `false`, checkboxes will be hidden, rather than disabled.

## Configure Selectable Rows

It is possible to specify which rows can be selected via the `rowSelection.isRowSelectable` callback function.

For instance if we only wanted to allow selection for rows where the 'year' property is less than 2007, we could implement the following:

```js
const gridOptions = {
    rowSelection: {
        mode: 'singleRow',
        isRowSelectable: (rowNode) => rowNode.data ? rowNode.data.year < 2007 : false,
        hideDisabledCheckboxes: true
    },

    // other grid options ...
}
```

Rows for which `isRowSelectable` returns `false` cannot be selected at all, whether using the UI or the API.

#### Configuring Selectable Rows

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([
  RowSelectionModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "year", maxWidth: 120 },
    { field: "athlete" },
    { field: "sport" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: {
    mode: "singleRow",
    hideDisabledCheckboxes: true,
    isRowSelectable: (rowNode) =>
      rowNode.data ? rowNode.data.year < 2007 : false,
  },
};

function toggleHideCheckbox() {
  gridApi.setGridOption("rowSelection", {
    mode: "singleRow",
    isRowSelectable: (rowNode) =>
      rowNode.data ? rowNode.data.year < 2007 : false,
    hideDisabledCheckboxes: getCheckboxValue("#toggle-hide-checkbox"),
  });
}

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

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi!.setGridOption("rowData", data));

function getCheckboxValue(id: string): boolean {
  return document.querySelector<HTMLInputElement>(id)?.checked ?? false;
}

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

[Live example: Configuring Selectable Rows](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-single-row/configure-selectable-rows/typescript/)

Note this example uses `hideDisabledCheckboxes` to hide disabled checkboxes, which can be toggled on or off.

## Customising the Checkbox Column

The checkbox column may be customised in a similar way to any other column, by specifying its column definition in the `selectionColumnDef` grid option.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selectionColumnDef` | `SelectionColumnDef` |  |  |  |

The `SelectionColumnDef` allows for a great deal of customisation, including custom renderers, sorting, tooltips and more. The example below demonstrates the following configuration:

- allowing sorting using the default sort order (selected first) via the header menu
- changing the default width of the column
- allowing resizing
- adding some header tooltip text

```js
const gridOptions = {
    selectionColumnDef: {
        sortable: true,
        resizable: true,
        width: 100,
        suppressHeaderMenuButton: false,
        headerTooltip: 'Checkboxes indicate selection',
    },

    // other grid options ...
}
```

#### Customising Checkbox Column

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionModule,
  TooltipModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([
  RowSelectionModule,
  TooltipModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

let gridApi: GridApi<IOlympicData>;

const gridOptions: GridOptions<IOlympicData> = {
  columnDefs: [
    { field: "athlete" },
    { field: "sport" },
    { field: "year", maxWidth: 120 },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowSelection: { mode: "singleRow" },
  selectionColumnDef: {
    sortable: true,
    resizable: true,
    width: 100,
    suppressHeaderMenuButton: false,
    headerTooltip: "Checkboxes indicate selection",
  },
};

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

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi.setGridOption("rowData", data));
```

[Live example: Customising Checkbox Column](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-single-row/customise-checkbox-column/typescript/)

> **Note**
>
> When sorting by the checkbox column, selecting a new row will not automatically update the row order, see [Change Detection](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/change-detection/#change-detection-and-sorting-filtering-grouping) for more information.

> **Note**
>
> The checkbox column is sized statically, and is therefore not affected by [Auto-Sizing](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/column-sizing/#auto-sizing-columns).

## Enable Click Selection & Deselection

The `rowSelection.enableClickSelection` property configures whether a row's selection state will be impacted when the row is clicked.

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `enableClickSelection` | `boolean \| 'enableDeselection' \| 'enableSelection'` |  |  |  |

This is typically used when [Checkbox Selection](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/row-selection-single-row/#removing-selection-checkboxes) is disabled, though both can be enabled simultaneously if desired. Click-selection and deselection can be enabled by setting `enableClickSelection` to `true`, otherwise they may be enabled separately using the values `'enableSelection'` and `'enableDeselection'`.

```js
const gridOptions = {
    rowSelection: {
        mode: 'singleRow',
        enableClickSelection: true,
    },

    // other grid options ...
}
```

The example below demonstrates the three possible configurations for this property, as well as the behaviour when it is disabled. Click a row to select it, or `^ Ctrl`-click a row to deselect it. Use the select element to switch between modes.

#### Disable Click Selection

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  RowSelectionModule,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";

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

ModuleRegistry.registerModules([
  RowSelectionModule,
  ClientSideRowModelModule,
  ColumnsToolPanelModule,
  ColumnMenuModule,
  ContextMenuModule,
  RowGroupingModule,
]);

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: "singleRow",
    enableClickSelection: true,
  },
};

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

fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
  .then((response) => response.json())
  .then((data: IOlympicData[]) => gridApi.setGridOption("rowData", data));

function onEnableClickSelection() {
  const value =
    document.querySelector<HTMLSelectElement>("#select-enable")?.value;

  gridApi.setGridOption("rowSelection", {
    mode: "singleRow",
    enableClickSelection:
      value === "true" ? true : value === "false" ? false : (value as any),
  });
}

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

[Live example: Disable Click Selection](https://www.ag-grid.com/archive/36.2.0/examples/row-selection-single-row/suppress-click-selection/typescript/)

> **Note**
>
> Note that deselection is still possible using the `␣ Space` key or when checkboxes are enabled by clicking a selected checkbox.

## API Reference

See the full list of configuration options available in `'singleRow'` 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'` |  |  |  |

## Row Selection with Enterprise Features

Row selection works with row grouping, tree data, and the server-side row model. See the relevant documentation sections:

- [Row Group Selection](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/grouping-row-selection/)
- [Tree Data Selection](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/tree-data-selection/)
- [Server-Side Row Model Selection](https://www.ag-grid.com/archive/36.2.0/javascript-data-grid/server-side-model-selection/)
