1

I'm trying to trigger my exportCSV from a different component outside of the TookkilProvider... is that possible? I did see some reference to this.refs.table.handleExportCSV(); here, but I can't seem to find that function

My code is below:

<ToolkitProvider
    keyField="id"
    data={[...data]}
    columns={Columns}
    exportCSV={{ onlyExportFiltered: true, exportAll: false }}
    search
>
    {
        props => (
            <div>
                <MyExportCSV {...props.csvProps} />
                <hr />
                <BootstrapTable keyField='id'
                    {...props.baseProps}
                    pagination={paginationFactory(options)} expandRow={expandRow}
                    ref={n => node = n} />

            </div>
        )
    }
</ToolkitProvider>
5
  • If you want trigger handleExportCSV() method from a different components, you must throw BootstrapTable ref to this components throught props. Commented Nov 23, 2021 at 16:23
  • How? I can't seem to find handleExportCSV() in the node ref, what do I need to pass? I'm not even able to trigger it from the same component, only inside the Toolkit. Am I missing something obvious?
    – JoelE
    Commented Nov 23, 2021 at 16:29
  • Method handleExportCSV available only in old version of react-bootstrap-table, in new version you must use onExport(). Demo react-bootstrap-table.github.io/react-bootstrap-table2/… Commented Nov 23, 2021 at 16:48
  • The link you sent is what I'm doing right now, and I'm calling the export from within the Toolkit how do I export the props from the toolkit so i can call it from somewhere else, ref on the table doesn't seem to be it
    – JoelE
    Commented Nov 24, 2021 at 5:55
  • Maybe my question wasn't clear, I'm trying to place the export button on another component(parent component)
    – JoelE
    Commented Nov 24, 2021 at 7:16

1 Answer 1

1

You can do it with useRef in parent and forwardRef in child components. Create custom MyExportCSV with hidden input and pass parent ref to it and call onExport() on click. Then on parent you can create button that will be on click trigger event click of child input. I wrote example for you. DEmo

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.