2
通过ag-Grid Cell Rendering documentation寻找后,我没有看到一个方法来通过cellRenderFramework
参数自定义属性添加到单元格渲染器。例如,我想将回调传递给在点击按钮时调用的自定义渲染器。AG-网格单元格渲染 - 自定义道具
class AddCellRenderer extends React.Component<ICellRendererParams, {}> {
/**
* Callback handle to pass data to on a click.
*/
public static callback = (data: MyData): void => { return; };
public constructor(params: ICellRendererParams) {
super(params);
}
public render() {
let className = 'pt-button pt-intent-success pt-icon-add';
let text = 'Click to add';
if (this.props.data.saved) {
className = 'pt-button pt-intent-danger pt-icon-remove';
text = 'Click to remove';
}
return (
<button type="button" onClick={this.onClick} className={className}>{text}</button>
);
}
private onClick = (event: React.FormEvent<HTMLButtonElement>): void => {
AddCellRenderer.callback(this.props.data);
this.setState({ ...this.state }); // Make React update the component.
}
}
而且我有一个使用它像另一个组件,以便
public render() {
let saveCellRenderer = AddCellRenderer;
saveCellRenderer.callback = this.onSelectData;
const columnDefs: ColDef[] = [
{
headerName: 'Add to Available Data',
cellRendererFramework: AddCellRenderer,
},
...
];
...
}
必须有另一种方式来传递这个回调是不是这是丑陋的静态公共方法等道具,并不会多,当工作组件使用渲染器,我该如何使用ag-Grid做这件事?
结束使用更高阶的组件来帮助解决这个问题。 – Lucas