有没有一种方法可以更改材质表(react.js)中的默认页面索引(0)

时间:2020-08-25 14:29:59

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

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

2 个答案:

答案 0 :(得分:1)

您可以将 initialPage 定义为options属性的一部分,可用于定义所需的内容。检查文档here

enter image description here

import MaterialTable from 'material-table';

<MaterialTable
// other props

    options={{
        initialPage: 1
       }}
/>

我希望对您有用!

答案 1 :(得分:0)

 ***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);
                };