Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call csv export as a function #1104

Closed
JWDobken opened this issue Mar 2, 2017 · 3 comments
Closed

call csv export as a function #1104

JWDobken opened this issue Mar 2, 2017 · 3 comments

Comments

@JWDobken
Copy link

JWDobken commented Mar 2, 2017

Is it possible to call the table export button as a function?

What I actually want is to generate the table and csv export from another page, without showing the table itself, and I think this would be an elegant solution.

MWE
This is my bootstrap data table with export button:

<BootstrapTable key="datatable" data={data} exportCSV csvFileName='table-export.csv'>
  <TableHeaderColumn dataField="dataType" isKey={true}>Data type</TableHeaderColumn>
  <TableHeaderColumn dataField="startedAt">Started at</TableHeaderColumn>
</BootstrapTable>

I would like to call a function, for example this.datatable.exportcsv()

@AllenFang
Copy link
Owner

check http://allenfang.github.io/react-bootstrap-table/docs.html#handleExportCSV, use react ref to call a exposed api

let me know if you have any question

@JWDobken
Copy link
Author

JWDobken commented Mar 7, 2017

@AllenFang actually I'm still struggling with the auto-CSV export without showing the table.

This works:

table = (
    <BootstrapTable
        ref={(table) => (this.props.directExport ? table.handleExportCSV() : '')}
        data={data}
        exportCSV
        csvFileName='locations.csv'>
    <TableHeaderColumn dataField="LocationID" isKey={true}>LocationID</TableHeaderColumn>
    <TableHeaderColumn dataField="ProjectID">ProjectID</TableHeaderColumn>
</BootstrapTable>)
renderTable = true
return (
  <div>
    {renderTable ? table : table.handleExportCSV()}
  </div>
);

but for specific reasons I would like to hide the table for the user

@AllenFang
Copy link
Owner

you should render table then call the function, because table is a reference on that react component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants