AG_HIHI
AG_HIHI

Reputation: 1995

How can I retrieve the Id of the selected column in ag-grid?

I have built this grid using ag-grid: enter image description here

I want to know when the user clicks on a specific cell the following:
- RowId
- ColumnId (The field attribute in the columns definitions)

So far I have only managed to collect the rowId this way:

Relevant html code:

  (rowClicked)="getRowId($event)"

Relevant TypeScript code:

  getRowId(chosenRow) {
    console.log('chosenRow.node: ', chosenRow.node); 
}

I am wondering if I can use a similar approach to detect which column the user has just selected?
Thank you!

Upvotes: 1

Views: 2311

Answers (2)

Dilani Alwis
Dilani Alwis

Reputation: 749

You can achieve this by simply listening to the grid cell clicked event as below.

 this.gridOptions.onCellClicked = ((event: CellClickedEvent) => {
     const rowId = event.rowIndex;
     const colId = event.column.colId;
 });

Upvotes: 2

AG_HIHI
AG_HIHI

Reputation: 1995

  (cellClicked)="updateDepartementsDropDownList($event);"

typescript :

 updateDepartementsDropDownList(params) {
    const colId = params.column.getId();
    console.log('colId: ', colId);

  }

Upvotes: 0

Related Questions