0
votes

How to set the ag-grid first row selected by default in angular.

here's the code: https://stackblitz.com/edit/ag-grid-angular-hello-world-xabqct?file=src/app/app.component.ts

I want the first row is selected by default when opening the application.

1

1 Answers

3
votes

You need to have a property to uniquely identify a record (eg. id) for this.

  1. Provide this function in your template.
[getRowNodeId]="_getRowNodeId"
_getRowNodeId(data) {
  return data.id;
}
  1. Provide this id for each object of rowData

  2. In onGridReady, call gridApi's getRowNode(id).selectThisNode(true) to select the first record.

this.gridApi.getRowNode(1).selectThisNode(true);

Check this updated StackBlitz for reference.