---
title: "Row Selection"
framework: vue
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.

```ts
<ag-grid-vue
    :rowSelection="rowSelection"
    /* other grid options ... */>
</ag-grid-vue>

this.rowSelection = {
    mode: 'singleRow',
};
```

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/vue-data-grid/row-selection-single-row/)
- [Multi-Row Selection](https://www.ag-grid.com/vue-data-grid/row-selection-multi-row/)

#### Enabling Row Selection

```ts
import {
  createApp,
  defineComponent,
  onBeforeMount,
  ref,
  shallowRef,
} from "vue";
import { AgGridVue } from "ag-grid-vue3";
import "./styles.css";
import {
  ClientSideRowModelModule,
  ColDef,
  ColGroupDef,
  GridApi,
  GridOptions,
  GridReadyEvent,
  ModuleRegistry,
  RowSelectionMode,
  RowSelectionModule,
  RowSelectionOptions,
  enableDevValidations,
} from "ag-grid-community";
import {
  ColumnMenuModule,
  ColumnsToolPanelModule,
  ContextMenuModule,
  RowGroupingModule,
} from "ag-grid-enterprise";
import { IOlympicData } from "./interfaces";
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

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

function getSelectValue(id: string): RowSelectionMode {
  return (
    (document.querySelector<HTMLSelectElement>(id)
      ?.value as RowSelectionMode) ?? "singleRow"
  );
}

const VueExample = defineComponent({
  template: `
        <div style="height: 100%">
                <div class="example-wrapper">
      <div class="example-header">
        <label>
          <span>Selection mode: </span>
          <select id="input-selection-mode" v-on:change="updateSelectionOptions()">
            <option value="singleRow">singleRow</option>
            <option value="multiRow">multiRow</option>
          </select>
        </label>
      </div>
      <ag-grid-vue
        style="width: 100%; height: 100%;"
        @grid-ready="onGridReady"
        :columnDefs="columnDefs"
        :defaultColDef="defaultColDef"
        :rowSelection="rowSelection"
        :rowData="rowData"></ag-grid-vue>
      </div>
        </div>
    `,
  components: {
    "ag-grid-vue": AgGridVue,
  },
  setup(props) {
    const gridApi = shallowRef<GridApi<IOlympicData> | null>(null);
    const columnDefs = ref<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 = ref<ColDef>({
      flex: 1,
      minWidth: 100,
    });
    const rowSelection = ref<RowSelectionOptions | "single" | "multiple">({
      mode: "singleRow",
    });
    const rowData = ref<IOlympicData[]>(null);

    function updateSelectionOptions() {
      gridApi.value.setGridOption("rowSelection", {
        mode: getSelectValue("#input-selection-mode"),
      });
    }
    const onGridReady = (params: GridReadyEvent) => {
      gridApi.value = params.api;

      const updateData = (data) => (rowData.value = data);

      fetch("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
        .then((resp) => resp.json())
        .then((data) => updateData(data));
    };

    return {
      gridApi,
      columnDefs,
      defaultColDef,
      rowSelection,
      rowData,
      onGridReady,
      updateSelectionOptions,
    };
  },
});

const app = createApp(VueExample);
app.mount("#app");
```

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

## 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/vue-data-grid/grouping-row-selection/)
- [Tree Data Selection](https://www.ag-grid.com/vue-data-grid/tree-data-selection/)
- [Server-Side Row Model Selection](https://www.ag-grid.com/vue-data-grid/server-side-model-selection/)
