【发布时间】:2019-03-05 22:24:22
【问题描述】:
我想在时间列定义时为 reactjs 中的 ag-grid 表列添加一个按钮。 onclick 我需要调用一个类函数。 我想创建 onclick 事件并将参数值传递给函数并从那里进行 api 调用。
columnDefs = [{
..... {
headerName: "View",
field: "id",
sortable: false,
filter: false,
colId: "view",
cellRendererFramework: function(params) {
return <Button onclick = {
this.handleClick
} > Test < /Button>
},
},
......
];
}
handleClick() {
console.log("some API call and state change");
}
render() {
return ( <
div >
<
div id = "myGrid"
style = {
{
height: "100%",
width: "100%"
}
}
className = "ag-theme-material" >
<
AgGridReact enableSorting = {
true
}
groupSelectsChildren = {
true
}
rowData = {
this.state.organization
}
columnDefs = {
this.columnDefs
}
onGridReady = {
this.onGridReady
} >
<
/AgGridReact>
<
/div>
}
export default OrganizationList;
【问题讨论】:
-
你真的认为问这样的问题会帮助我们理解实际问题吗?至少分享你尝试过的代码
-
这对我有用
cellRendererFramework: (props) => { return ( <button onClick{this.handleClick.bind(this)>Click</button> } ); }
标签: reactjs ag-grid-react