Configure the grid to allow users to select rows by clicking them, focusing a row and pressing ␣ Space or via API.
Enabling Row Selection Copy Link
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.
<ag-grid-angular
[rowSelection]="rowSelection"
/* other grid options ... */ />
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:
import { Component } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { AgGridAngular } from "ag-grid-angular";
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";
if (process.env.NODE_ENV !== "production") {
enableDevValidations();
}
ModuleRegistry.registerModules([
RowSelectionModule,
ClientSideRowModelModule,
ColumnsToolPanelModule,
ColumnMenuModule,
ContextMenuModule,
RowGroupingModule,
]);
import { IOlympicData } from "./interfaces";
@Component({
selector: "my-app",
standalone: true,
imports: [AgGridAngular],
template: `<div class="example-wrapper">
<div class="example-header">
<label>
<span>Selection mode: </span>
<select id="input-selection-mode" (change)="updateSelectionOptions()">
<option value="singleRow">singleRow</option>
<option value="multiRow">multiRow</option>
</select>
</label>
</div>
<ag-grid-angular
style="width: 100%; height: 100%;"
[columnDefs]="columnDefs"
[defaultColDef]="defaultColDef"
[rowSelection]="rowSelection"
[rowData]="rowData"
(gridReady)="onGridReady($event)"
/>
</div> `,
})
export class AppComponent {
private gridApi!: GridApi<IOlympicData>;
columnDefs: 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" },
];
defaultColDef: ColDef = {
flex: 1,
minWidth: 100,
};
rowSelection: RowSelectionOptions | "single" | "multiple" = {
mode: "singleRow",
};
rowData!: IOlympicData[];
constructor(private http: HttpClient) {}
updateSelectionOptions() {
this.gridApi.setGridOption("rowSelection", {
mode: getSelectValue("#input-selection-mode"),
});
}
onGridReady(params: GridReadyEvent<IOlympicData>) {
this.gridApi = params.api;
this.http
.get<
IOlympicData[]
>("https://www.ag-grid.com/example-assets/small-olympic-winners.json")
.subscribe((data) => (this.rowData = data));
}
}
function getSelectValue(id: string): RowSelectionMode {
return (
(document.querySelector<HTMLSelectElement>(id)
?.value as RowSelectionMode) ?? "singleRow"
);
}
.example-wrapper {
display: flex;
flex-direction: column;
height: 100%;
}
.example-header {
margin-bottom: 10px;
}
#myGrid {
flex: 1 1 0px;
width: 100%;
}
import '@angular/compiler';
import { provideHttpClient } from '@angular/common/http';
import { enableProdMode } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
if (new URLSearchParams(window.location.search).get('prod') !== 'false') {
enableProdMode();
}
const app = bootstrapApplication(AppComponent, {
providers: [provideHttpClient()],
});
export interface IOlympicData {
athlete: string,
age: number,
country: string,
year: number,
date: string,
sport: string,
gold: number,
silver: number,
bronze: number,
total: number
} Row Selection with Enterprise Features Copy Link
Row selection can be used when using row grouping, tree data and the server-side row model. See the respective sections of the documentation: