Search code examples
angularag-grid

Ag-Grid : How to get the value of the cell on clicking the cell


how can I get the value of the cell when the cell is clicked clicked in Angular?

this is my HTML :

    <ag-grid-angular  
    style="width: 100%; height: 300px;" 
    class="ag-theme-alpine"
    [rowData]="list" 
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [pagination]="true"
    [modules]="modules"
    >
    </ag-grid-angular>

Solution

  • Listen to cellClicked event https://www.ag-grid.com/angular-data-grid/grid-events/

    <ag-grid-angular  
    style="width: 100%; height: 300px;" 
    class="ag-theme-alpine"
    [rowData]="list" 
    [columnDefs]="columnDefs"
    [defaultColDef]="defaultColDef"
    [pagination]="true"
    [modules]="modules"
    (cellClicked)="onCellClicked($event)"
    >
    </ag-grid-angular>
    
    onCellClicked(cellData){
      console.log(cellData.value)
    }