正如ag Grid文档中提到的,ag Grid将一些默认道具传递给每个单元渲染器,这些道具的格式为
IcellRenderParams
,
interface ICellRendererParams {
value: any, // value to be rendered
valueFormatted: any, // value to be rendered formatted
getValue: () => any, // convenience function to get most recent up to date value
setValue: (value: any) => void, // convenience to set the value
formatValue: (value: any) => any, // convenience to format a value using the column's formatter
data: any, // the row's data
node: RowNode, // row node
colDef: ColDef, // the cell's column definition
column: Column, // the cell's column
rowIndex: number, // the current index of the row (this changes after filter and sort)
api: GridApi, // the grid API
eGridCell: HTMLElement, // the grid's cell, a DOM div element
eParentOfValue: HTMLElement, // the parent DOM item for the cell renderer, same as eGridCell unless using checkbox selection
columnApi: ColumnApi, // grid column API
context: any, // the grid's context
refreshCell: () => void // convenience function to refresh the cell
}
详情请参见,
https://www.ag-grid.com/javascript-grid-cell-rendering-components/#cell-renderer-component
所以,有一个属性叫做
数据
它指向指向单元格渲染器所在索引的行数据(在本例中为单击的行数据)。
所以你的单元渲染器可以直接使用这个道具作为
道具。数据
,
/* Here the props will point to ICellRendererParams */
const EditMagnifier = (props) =>
{
const printRowData = (event) => {
/* This will give you the complete row data for the clicked row*/
console.log(props.data);
}
return (
<IconButton iconSvg={search} onClick={printRowData}/>
)
}