简体   繁体   English

如何让我的 React 表始终重置为第 1 页?

[英]How can I get my React table to always reset to page 1?

My react table shows data based on 2 or 3 different filters the user picks.我的反应表显示基于用户选择的 2 或 3 个不同过滤器的数据。 Every time the search filters are changed and the table's data is updated, the table begins by displaying the page number that was last looked at.每次更改搜索过滤器并更新表格数据时,表格都会首先显示上次查看的页码。 How can I make sure the table always starts at page 1 every time the search filters are changed?每次更改搜索过滤器时,如何确保表格始终从第 1 页开始?

React table code:反应表代码:

<ReactTable
                    data={this.props.summarydata}
                    columns = {columns}
                    defaultPageSize = {40}
                    pageSizeOptions = {[20, 50, 100, 500]}
                    style={getStyle}
                    loadingText = {"Loading..."}
                    noDataText={"No data found. Please edit search parameters."}
                    minRows={10}
                    resizable={true}
                    previousText = {"Previous"}               
                >
                    {(state, filteredData, instance) => {
                        this.ReactTable = state.pageRows.map(post => { return post._original});
                        return(
                            <div>
                                {filteredData()}
                            </div>
                        )
                    }}

                </ReactTable>      

As per the docs you can add the autoResetPage prop to your table options object like this,根据文档,您可以像这样将autoResetPage道具添加到您的表格选项对象中,

<ReactTable
                    data={this.props.summarydata}
                    columns = {columns}
// This one!
                    autoResetPage={true}
                    defaultPageSize = {40}
                    pageSizeOptions = {[20, 50, 100, 500]}
                    style={getStyle}
                    loadingText = {"Loading..."}
                    noDataText={"No data found. Please edit search parameters."}
                    minRows={10}
                    resizable={true}
                    previousText = {"Previous"}               
                >
                    {(state, filteredData, instance) => {
                        this.ReactTable = state.pageRows.map(post => { return post._original});
                        return(
                            <div>
                                {filteredData()}
                            </div>
                        )
                    }}

                </ReactTable> 
    const {
        getTableProps,
        getTableBodyProps,
        headerGroups,
        rows,
        page,
        prepareRow,
        filters,
        allColumns,
        setFilter,
        selectedFlatRows,
        // below new props related to 'usePagination' hook
        canPreviousPage,
        canNextPage,
        pageOptions,
        pageCount,
        gotoPage,
        nextPage,
        previousPage,
        setPageSize,
        state: {pageIndex, pageSize},
    } = useTable(
        {
            columns,
            data,
            defaultColumn: {
                Filter: DefaultColumnFilter,
            },
            filterTypes,
// This is the one you want.
            autoResetPage,
                hiddenColumns: columns.filter((col: any) => col.show === false).map((col) => col.id || col.accessor),
                pageIndex: 0,
                pageSize: 20,
            },
        },
        ...hooks
    );

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

相关问题 我怎样才能得到我在反应表中的行的 ID? - how can i get the id of my rows in react-table? React-如何获取更新的数据以显示在表中? - React - how can I get updated data to show in my table? 请帮助,我无法让我的重置按钮工作-React js - Please help, I can't get my reset button to work- React js 如何为我的反应应用程序重置所有 git 命令并从新开始? - how can i reset all my git commands for my react app and start from new? 如何让我的 React 应用程序在链接预览中正确发送页面标题? 使用 NGINX 作为代理 - How can I get my React App to correctly send page title in link previews? Using NGINX as proxy 如何让我的产品页面使用 React --&gt; Navigate 进行刷新? - How can I get my product page to work on refresh with React -->Navigate? React-如何在表中进行重新渲染? - React - How can I get a re-render to happen in my table? 如何将此React表单呈现到我的页面上? - How do I get this React form to render onto my page? 如何在 React Js 中仅重新加载表格而不是整个页面 - How can I reload just the table not the whole page in React Js 我在 reactjs 的重置方法中遇到错误。 我如何根据我的编码在反应中使用该方法 - Im facing error in reset method in reactjs. How can i use that method according to my coding in react
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM