Adithya Sundar
Adithya Sundar

Reputation: 21

Is there a way to change the default page index(0) in material table (reactjs)

the default page index seems to be '0' in material table , but the api im working with starts off from page index '1' , how can i change the default page index of the table to as that of API

Upvotes: 2

Views: 2485

Answers (2)

Shahnad S
Shahnad S

Reputation: 1167

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

Upvotes: 1

NicoE
NicoE

Reputation: 4863

You can define initialPage as part of the options property which you can use to define what you need. Check the docs here.

enter image description here

import MaterialTable from 'material-table';

<MaterialTable
// other props

    options={{
        initialPage: 1
       }}
/>

I hope that works for you!

Upvotes: 2

Related Questions