我正在使用material-ui库并制作数据表。对于数据表,我正在使用这个库mui-datatables。我需要调用 API 来检索数据并在表格中显示。我在控制台中检查了数据即将到来但未显示在数据表中。
下面是我的代码:
state = {
students: [],
rows: []
};
componentDidMount() {
document.title = "List of students";
axios
.get("api.url")
.then(res => {
this.setState({ students: res.data }, () => {
this.state.students.forEach((value, index) => {
this.state.rows.push({
digitalcredid: value.studentid,
firstname: value.firstname,
lastname: value.lastname,
email: value.email,
nationality: value.nationality,
postaladress: value.postaladress,
nic: value.nic
});
});
});
});
}
并显示如下数据:
const options = {
filterType: "checkbox",
serverSide: true,
print: false
};
<div className="row">
<div className="col-12">
<MUIDataTable
title={"Student List"}
data={this.state.rows}
columns={studentColumns}
options={options}
/>
</div>
</div>
如果有人帮助我,那就太好了。