Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update ReactHTMLTableToExcel.jsx
Fixed component for auto download
  • Loading branch information
ciuliene authored Jan 7, 2021
commit 5e4291ef3c4f068f398f59ecb4375e97eb9bd401
7 changes: 7 additions & 0 deletions src/ReactHTMLTableToExcel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const propTypes = {
id: PropTypes.string,
className: PropTypes.string,
buttonText: PropTypes.string,
autoDownload: PropTypes.bool,
};

const defaultProps = {
id: 'button-download-as-xls',
className: 'button-download',
buttonText: 'Download',
autoDownload: false,
};

class ReactHTMLTableToExcel extends Component {
Expand All @@ -23,6 +25,10 @@ class ReactHTMLTableToExcel extends Component {
this.handleDownload = this.handleDownload.bind(this);
}

componentDidMount() {
if (this.props.autoDownload) this.handleDownload();
}

static base64(s) {
return window.btoa(unescape(encodeURIComponent(s)));
}
Expand Down Expand Up @@ -94,6 +100,7 @@ class ReactHTMLTableToExcel extends Component {
}

render() {
if (this.props.autoDownload) return null;
return (
<button
id={this.props.id}
Expand Down