4

If a user click or select a row in ag-grid then I want to fire a click event. I searched the doc but no luck.

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230
Rahul Kant
  • 137
  • 1
  • 1
  • 9

1 Answers1

3

It's called onRowClicked and onRowSelected respectively. onRowClicked will be called when you click a row even if you disable row selection. onRowSelected on the other hand only fires when a row is selected

<AgGridReact
  columnDefs={columnDefs}
  onRowSelected={(e) => console.log("row selected", e.rowIndex)}
  onRowClicked={(e) => console.log("row clicked", e.rowIndex)}
  rowSelection="multiple"
  rowData={rowData}
/>

Another way is to catch all of the ag-grid events using GridApi.addGlobalListener() and filter out the ones you're not interested in.

const onGridReady = (params: GridReadyEvent) => {
  params.api.addGlobalListener((type: string, e) => {
    if (type === "rowClicked" || type === "rowSelected") {
      console.log(type, "from global event handler");
    }
  });
};

Live Demo

Edit smoosh-hill-evpq3

NearHuscarl
  • 66,950
  • 18
  • 261
  • 230