【发布时间】:2021-09-13 17:51:57
【问题描述】:
我是使用 ag-grid 的新手,并且正在将它实施到我的 React 项目中。有了这个,我制作了下表:
class Table extends Component {
constructor(props) {
super(props)
this.state = {
columnDefs: [
{ headerName: "Column 1", field: "col1"},
],
rowData: [
{ 'col1': 'Hello'},
{ 'col1': 'World'},
],
}
}
render() {
return (
<div className="ag-theme-alpine" style={{ height: 400, width: 605 }}>
<AgGridReact
columnDefs={this.state.columnDefs}
rowData={this.state.rowData}>
</AgGridReact>
</div>
);
}
};
现在,我可以使用.fetch 获取 JSON,并希望将 JSON 值加载到我的表中。例如,假设我的 JSON 是这样输入的:
{'col1': 'Jeff',
'col1' : 'Sophie',
'col1' : 'Kelly'}
如何将这些值加载到上面的表格中?我尝试将以下 componentDidMount 方法添加到表中,但表随后会自行变灰并显示“正在加载...”并且永远不会完成加载:
componentDidMount(){
myData= getData() //method calls fetch and returns my JSON items
this.setState({
rowData: myData
});
}
【问题讨论】:
标签: javascript reactjs ag-grid