【发布时间】:2021-01-25 17:11:54
【问题描述】:
如何通过传递选定的行数据作为道具重定向到另一个页面?
我正在使用材料表,我想在单击“导出”按钮后将选定的行数据传递到另一个页面,以便我可以使用该数据在另一个页面中创建某种报告。
我认为我应该使用 history.push() 方法,但它在 onClick 方法中不起作用。有人可以给我任何提示吗?
import React from 'react'
import MaterialTable from 'material-table';
class LeadTable extends React.Component{
constructor(props) {
super(props);
this.state = {
leads : [],
};
}
componentDidMount() {
fetch('http://localhost:5000/api/Leads')
.then(res => res.json())
.then((data) => {
// console.log('Data: ', data[0])
this.setState({
leads: data[0]
})
})
.catch(console.log);
}
redirectToReport = () => {
const { history } = this.props;
history.push('report');
}
render(){
return (
<div style={{ maxWidth: '100%' , align: 'center'}}>
<MaterialTable
title="Reporting"
columns={[
...
]}
data = {this.state.leads}
options={{
selection: true,
filtering: true,
sorting: true
}}
actions = {[{
position: "toolbarOnSelect",
tooltip: 'Export the selected activities!',
icon: 'Export',
onClick: (event, rowData) => {
console.log("Row Data: " , rowData)
// rowData has all the selected row and I want to redirect to another page with passing those data.
}
}]}
/>
</div>
)}
}
export default LeadTable
【问题讨论】:
标签: javascript reactjs material-ui material-table