Theme

Examples › Pagination

DustinSawaynDustin.Sawayn@yahoo.comMay 20 1980
EarnestHellerEarnest6@yahoo.comNov 26 1991
SheilaKesslerSheila.Kessler@hotmail.comApr 12 1982
BrayanMacejkovicBrayan3@hotmail.comJun 30 1946
AssuntaAnkundingAssunta79@gmail.comMay 26 1978
JavonteSchummJavonte14@gmail.comMar 4 1956
JenniferVonJennifer_Von87@hotmail.comFeb 22 1985
MozellBeckerMozell.Becker@yahoo.comSep 20 1974
HoraceBayerHorace.Bayer24@yahoo.comJul 4 1996
ChaunceyHoegerChauncey.Hoeger7@gmail.comApr 8 1982
RemingtonHansenRemington.Hansen9@yahoo.comApr 17 1967
SammyMayerSammy.Mayer19@yahoo.comJul 12 1972
MarilouMorarMarilou.Morar@gmail.comJul 30 1974
ArmandoZiemeArmando_Zieme@gmail.comOct 8 1976
DakotaLittleDakota.Little@gmail.comSep 1 1977
1 - 15 / 500
No records
You can enable pagination by adding the following component properties:
  • page → the current page number
  • onPageChange → a callback that is executed when the user changes the current page
  • totalRecords → the total number of records in the dataset
  • recordsPerPage → the number of records per page
If you’re not happy with the default pagination behavior, you can override it by setting these optional properties:
  • loadingText → a string to display while loading records
  • noRecordsText → a string to display when no records are present
  • paginationText → a callback receiving an object in the shape of { from: number; to: number; totalRecords: number } and returning a ReactNode representing the pagination text
  • paginationColor → the pagination color; see Mantine Colors
  • paginationSize → the pagination size, 'xs' | 'sm' | 'md' | 'lg' | 'xl'
  • paginationWrapBreakpoint → a breakpoint below which the pagination footer content will wrap on multiple lines; defaults to sm
import { Box } from '@mantine/core';
import dayjs from 'dayjs';
import { DataTable } from 'mantine-datatable';
import { useEffect, useState } from 'react';
import employees from '~/data/employees.json';
const PAGE_SIZE = 15;
export default function PaginationExample() {
const [page, setPage] = useState(1);
const [records, setRecords] = useState(employees.slice(0, PAGE_SIZE));
useEffect(() => {
const from = (page - 1) * PAGE_SIZE;
const to = from + PAGE_SIZE;
setRecords(employees.slice(from, to));
}, [page]);
return (
<Box sx={{ height: 300 }}>
<DataTable
withBorder
records={records}
columns={[
{ accessor: 'firstName', width: 100 },
{ accessor: 'lastName', width: 100 },
{ accessor: 'email', width: '100%' },
{
accessor: 'birthDate',
textAlignment: 'right',
width: 120,
render: ({ birthDate }) => dayjs(birthDate).format('MMM D YYYY'),
},
]}
totalRecords={employees.length}
recordsPerPage={PAGE_SIZE}
page={page}
onPageChange={(p) => setPage(p)}
// uncomment the next line to use a custom loading text
// loadingText="Loading..."
// uncomment the next line to display a custom text when no records were found
// noRecordsText="No records found"
// uncomment the next line to use a custom pagination text
// paginationText={({ from, to, totalRecords }) => `Records ${from} - ${to} of ${totalRecords}`}
// uncomment the next line to use a custom pagination color (see https://mantine.dev/theming/colors/)
// paginationColor="grape"
// uncomment the next line to use a custom pagination size
// paginationSize="md"
/>
</Box>
);
}

Displaying a page size selector

You can display a selector to let the user choose the page size by setting the following component properties:
  • recordsPerPageOptions → an array of page size numbers to display in the page size selector
  • onRecordsPerPageChange → a callback that is executed when the user changes the page size
  • recordsPerPageLabel → the page size selector label, defaulting to 'Records per page'
import { Box } from '@mantine/core';
import dayjs from 'dayjs';
import { DataTable } from 'mantine-datatable';
import { useEffect, useState } from 'react';
import employees from '~/data/employees.json';
const PAGE_SIZES = [10, 15, 20];
export default function PaginationExampleWithPageSizeSelector() {
const [pageSize, setPageSize] = useState(PAGE_SIZES[1]);
useEffect(() => {
setPage(1);
}, [pageSize]);
const [page, setPage] = useState(1);
const [records, setRecords] = useState(employees.slice(0, pageSize));
useEffect(() => {
const from = (page - 1) * pageSize;
const to = from + pageSize;
setRecords(employees.slice(from, to));
}, [page, pageSize]);
return (
<Box sx={{ height: 300 }}>
<DataTable
withBorder
records={records}
columns={[
{ accessor: 'firstName', width: 100 },
{ accessor: 'lastName', width: 100 },
{ accessor: 'email', width: '100%' },
{
accessor: 'birthDate',
textAlignment: 'right',
width: 120,
render: ({ birthDate }) => dayjs(birthDate).format('MMM D YYYY'),
},
]}
totalRecords={employees.length}
paginationColor="grape"
recordsPerPage={pageSize}
page={page}
onPageChange={(p) => setPage(p)}
recordsPerPageOptions={PAGE_SIZES}
onRecordsPerPageChange={setPageSize}
/>
</Box>
);
}
DustinSawaynDustin.Sawayn@yahoo.comMay 20 1980
EarnestHellerEarnest6@yahoo.comNov 26 1991
SheilaKesslerSheila.Kessler@hotmail.comApr 12 1982
BrayanMacejkovicBrayan3@hotmail.comJun 30 1946
AssuntaAnkundingAssunta79@gmail.comMay 26 1978
JavonteSchummJavonte14@gmail.comMar 4 1956
JenniferVonJennifer_Von87@hotmail.comFeb 22 1985
MozellBeckerMozell.Becker@yahoo.comSep 20 1974
HoraceBayerHorace.Bayer24@yahoo.comJul 4 1996
ChaunceyHoegerChauncey.Hoeger7@gmail.comApr 8 1982
RemingtonHansenRemington.Hansen9@yahoo.comApr 17 1967
SammyMayerSammy.Mayer19@yahoo.comJul 12 1972
MarilouMorarMarilou.Morar@gmail.comJul 30 1974
ArmandoZiemeArmando_Zieme@gmail.comOct 8 1976
DakotaLittleDakota.Little@gmail.comSep 1 1977
1 - 15 / 500
Records per page
No records

Using pagination control props

You can provide additional props to pagination controls by using the getPaginationControlProps callback. For example, if you’re not happy with the default accesibility aria-labels, you can override them like so:
<DataTable
// other props...
getPaginationControlProps={(control) => {
if (control === 'previous') {
const title = 'Go to previous page';
return { title, 'aria-label': title };
} else if (control === 'next') {
const title = 'Go to next page';
return { title, 'aria-label': title };
}
return {};
}}
/>
DustinSawaynDustin.Sawayn@yahoo.comMay 20 1980
EarnestHellerEarnest6@yahoo.comNov 26 1991
SheilaKesslerSheila.Kessler@hotmail.comApr 12 1982
BrayanMacejkovicBrayan3@hotmail.comJun 30 1946
AssuntaAnkundingAssunta79@gmail.comMay 26 1978
JavonteSchummJavonte14@gmail.comMar 4 1956
JenniferVonJennifer_Von87@hotmail.comFeb 22 1985
MozellBeckerMozell.Becker@yahoo.comSep 20 1974
HoraceBayerHorace.Bayer24@yahoo.comJul 4 1996
ChaunceyHoegerChauncey.Hoeger7@gmail.comApr 8 1982
RemingtonHansenRemington.Hansen9@yahoo.comApr 17 1967
SammyMayerSammy.Mayer19@yahoo.comJul 12 1972
MarilouMorarMarilou.Morar@gmail.comJul 30 1974
ArmandoZiemeArmando_Zieme@gmail.comOct 8 1976
DakotaLittleDakota.Little@gmail.comSep 1 1977
1 - 15 / 500
No records

Mantine DataTable is trusted by

MIT LicenseSponsor the author
Built by Ionut-Cristian Florescu and these awesome people.
Please sponsor the project if you find it useful.
GitHub StarsNPM Downloads