简体   繁体   English

如何获取反应表过滤/排序的数据

[英]how to get react-table filtered/sorted data

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 .我想获取react-table的过滤数据我找到了一些答案Can't access resolved data in react-tableAccess filtered data in ReactTableError access encrypted 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 .但他们都在使用<ReactTable... ><ReactTableComponent...>并通过寻址表的ref ,他们将数据作为tableRef.getResolvedState().sortedData

my table looks like this and I have no <ReactTable...> .我的表看起来像这样,我没有<ReactTable...>

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

you can use rows as rows.values to the values.您可以将用作值的rows.values as first prepareRow(row) each row then return the values of the row.首先prepareRow(row)每一行然后返回该行的values

I assume you want to export filtered data as CVS.我假设您想将过滤后的数据导出为 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>



声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM