具有分页功能的ReactJS BootstrapTable不适用于ExportCSV

时间:2019-10-16 22:24:01

标签: reactjs export-to-csv bootstrap-table react-bootstrap-table

我正在使用带有分页功能的ReactJS BootstrapTable。效果很好,但我的用户希望能够将表上的数据导出到Excel电子表格。我集成了Bootstrap ExportCSV ToolkitProvider。仅当我没有分页时才有效。

<ToolkitProvider
              keyField="id"
              data={ products}
              columns={ columns }
              exportCSV
            >
              {
                props => (
                  <div>
                    <ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
                    <hr />

                    <BootstrapTable { ...props.baseProps } noDataIndication={ noDataFunction } />

                    </div>
                )
              }
            </ToolkitProvider>

添加分页时,出现此错误:

csv.js:120 Uncaught TypeError: Cannot read property 'get' of null
    at u.handleExportCSV (csv.js:120)
    at onClick (button.js:57)
    at Object.<anonymous> (react-dom.production.min.js:49)
    at p (react-dom.production.min.js:69)
    at react-dom.production.min.js:73
    at C (react-dom.production.min.js:140)
    at P (react-dom.production.min.js:169)
    at T (react-dom.production.min.js:158)
    at N (react-dom.production.min.js:232)
    at On (react-dom.production.min.js:1718)

这是我的分页代码:

<ToolkitProvider
              keyField="id"
              data={ products}
              columns={ columns }
              exportCSV
            >
              {
                props => (
                  <div>
                    <ExportCSVButton { ...props.csvProps }>Export CSV!!</ExportCSVButton>
                    <hr />
                    <PaginationProvider pagination={ paginationFactory(paginationOption) }>
                    {
                      ({
                        paginationProps,
                        paginationTableProps
                      }) => (
                        <div>                         
                                <BootstrapTable headerClass={ headerClass }
                                  noDataIndication={ noDataFunction }

                                  striped
                                  hover
                                  keyField='id' 
                                  data={ products} 
                                  columns={ columns } 
                                  filter={ filterFactory() } 
                                { ...paginationTableProps }           
                                />

                                {paginationProps.dataSize > 0 && 
                                    <PaginationListStandalone { ...paginationProps  } />        
                                }
                                {paginationProps.dataSize > 0 && 
                                    <SizePerPageDropdownStandalone { ...paginationProps } />        
                                }


                                { paginationProps.dataSize > 0 && 
                                    <PaginationTotalStandalone { ...paginationProps } />        
                                }
                        </div>
                      )
                    }
                </PaginationProvider> 
                  </div>
                )
              }
            </ToolkitProvider>

1 个答案:

答案 0 :(得分:0)

请检查您的进口。这些是必需的进口

import ToolkitProvider, {  CSVExport } from 'react-bootstrap-table2-toolkit';

import paginationFactory from 'react-bootstrap-table2-paginator';

const { ExportCSVButton } = CSVExport;

也代替PaginationProvider 您还可以将道具放置在

<BootstrapTable pagination={paginationFactory()} >