I'm trying to return the row data when a cell is clicked in ag-Grid. I have defined the following component that I pass into the cellRendererFramework
shown further down.
import { ICellRendererParams } from "ag-grid-community";
import * as React from "react";
import { CellValue } from "./ClickableCell.style";
export default class ClickableCell extends React.Component<ICellRendererParams> {
public render() {
return (
// this works when the clickable cell is clicked
// but i'm trying to return this data to the component that will be rendering the grid
<div onClick={() => console.log(this.props.data)}>
{this.props.value}
</div>
);
}
}
The following is in the component that defines the column header and row data.
const headers = [
{ headerName: "Name", field: "name", cellRendererFramework: ClickableCell },
{ headerName: "Age", field: "age" },
];
How can I go about receiving the clicked row data in this component, where the headers are defined? Thanks!
EDIT:
I've added a somewhat working version of the code: https://codesandbox.io/s/7qlvyk901