【问题标题】:Is there a way to change the default page index(0) in material table (reactjs)有没有办法更改材料表(reactjs)中的默认页面索引(0)
【发布时间】:2020-12-14 06:41:19
【问题描述】:

材料表中的默认页面索引似乎是'0',但是我使用的api从页面索引'1'开始,我如何将表的默认页面索引更改为API的默认页面索引

【问题讨论】:

  • 是的!这对材料表中的分页很有用,但是我使用材料 ui 的组件进行分页,我无法找到应该在那里更改初始页面的方法。感谢并抱歉注意准确!

标签: javascript reactjs pagination material-ui material-table


【解决方案1】:

您可以将 initialPage 定义为选项属性的一部分,您可以使用它来定义您需要的内容。查看文档here。

import MaterialTable from 'material-table';

<MaterialTable
// other props

    options={{
        initialPage: 1
       }}
/>

希望对你有用!

【讨论】:

    【解决方案2】:
     ***The Best way is***
    
        import { TablePagination} from "@material-ui/core";
        const [page, setPage] = React.useState(1);
    
       <TablePagination page={page - 1} onChangePage={handleChangePage}  />
       
         const handleChangePage = (event, newPage) => {
                        setPage(newPage + 1);
                    };
    

    【讨论】:

    • 它对我来说非常有用。谢谢@Shahnad。
    猜你喜欢
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    相关资源
    最近更新 更多