---
title: "Row Selection"
framework: javascript
version: "36.1.0"
---

# Row Selection

Configure the grid to allow users to select rows by clicking them, focusing a row and pressing `␣ Space` or via API.

## Enabling Row Selection

Row selection is configured with the `rowSelection` grid property. Setting `rowSelection.mode` to either `'multiRow'` or `'singleRow'` will allow you to select rows by clicking, focusing a row and pressing `␣ Space`, or via the selection API.

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

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

The following example illustrates a basic row selection configuration. Use the select control to choose the default single row or multi-row configuration.

See detailed documentation on the two row selection modes:

- [Single Row Selection](https://www.ag-grid.com/javascript-data-grid/row-selection-single-row/)
- [Multi-Row Selection](https://www.ag-grid.com/javascript-data-grid/row-selection-multi-row/)

#### Enabling Row Selection

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

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  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",
  },
};

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 getSelectValue(id: string): RowSelectionMode {
  return (
    (document.querySelector<HTMLSelectElement>(id)
      ?.value as RowSelectionMode) ?? "singleRow"
  );
}

function updateSelectionOptions() {
  gridApi.setGridOption("rowSelection", {
    mode: getSelectValue("#input-selection-mode"),
  });
}

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

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

## Row Selection with Enterprise Features

Row selection can be used when using row grouping, tree data and the server-side row model. See the respective sections of the documentation:

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