I am using antd table
and I would like to export data to csv
so I used the react-csv
and It worked. But after adding the react-csv
, my antd table is too slow to select the row, scroll. If I remove the react-csv
, table is fast enough.
Here is how I used:
import React from 'react';
import {Modal,Button} from 'react-bootstrap';
import {Table} from 'antd';
import * as ts_api from '../../api/ts/ts_api';
import 'antd/dist/antd.css';
import moment from 'moment';
import { CSVLink } from "react-csv";
const { Column, ColumnGroup } = Table;
export default class Monthly_Viewer extends React.Component{
constructor(props){
super(props);
this.state={
showmodel : true,
timesheetlist : [],
}
this.handleModelShow = this.handleModelShow.bind(this);
}
componentDidMount(){
ts_api.getallby_datefromto_empfromto_cscfromto(fromdate,todate,fromemp,toemp,fromcsc,tocsc).then((res)=>{
console.log("here");
this.setState({
timesheetlist : res,
exporttimesheetlist : res
});
})
}
handleModelShow = event => {
if(event && event.target.id === "close"){
this.setState({
showmodel : !this.state.showmodel
})
}
}
render(){
return(
<div>
<Modal show={this.state.showmodel}
onHide={this.handleModelShow}
dialogClassName="mtd-viewdialog"
>
<Modal.Header closeButton>
</Modal.Header>
<Modal.Body >
<Table dataSource={this.state.timesheetlist}
rowKey="id"
size="small"
bordered
scroll={{ x: 'max-content' , y:450}}
pagination = {{pageSizeOptions : ['10','30','60','100'], showSizeChanger:true}}
>
<Column title="Employee ID" dataIndex="empid" key="empid" width={120} defaultSortOrder="descend" sorter={(a,b)=> a.empid - b.empid} fixed="left"/>
<Column title="Employee Name" dataIndex="empname" key="empname" width={250} defaultSortOrder="descend" sorter={(a,b)=> a.empname?a.empname.localeCompare(b.empname):1} fixed="left"/>
<Column title="Date" dataIndex="tdate" key="tdate" width={100}
render={date=>(
moment(date).format("DD/MM/YYYY")
)}
sorter={(a,b)=>a.tdate.localeCompare(b.tdate)}
fixed="left"
/>
</Table>
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.handleModelShow} id="close" >
Close
</Button>
<CSVLink filename={"Time Detail Report.csv"} data={this.state.timesheetlist} className="btn btn-primary">Download me</CSVLink>
</Modal.Footer>
</Modal>
</div>
)
}
}
And I got a warning :
Warning: componentWillReceiveProps has been renamed, and is not recommended for use.............
Please update the following components: CSVLink
Is there any wrong in my render? why react-csv
make table slow?