how to get react-table filtered/sorted data

Viewed 95

I want to get the filtered data of react-table I found some answers Can't access resolved data in react-table, Access filtered data in ReactTable and Error accessing filtered data in React Table.

but they all are using <ReactTable ... > or <ReactTableComponent ...> and with addressing the ref of the table they got data as tableRef.getResolvedState().sortedData.

my table looks like this and I have no <ReactTable ...>.

  • tableRef returns the <table class="table table-striped" role="table"> ....
  • tableRef.current return undefined
  • tabelRef.getResolvedState() returns undefined
1 Answers

you can use rows as rows.values to the values. as first prepareRow(row) each row then return the values of the row.

I assume you want to export filtered data as CVS.

import { CSVLink, CSVDownload } from "react-csv";
...

<CSVLink
  data={rows.map(row=> {
    prepareRow(row)
    return row.values;
  })}
>

  <button
    type="button"
    className="btn btn-round btn-outline-secondary mr-2"
  >
    <i className="ri-file-4-line" />
  </button>
</CSVLink>



Related