Examples › Pagination

To enable pagination, set the following Mantine DataTable properties:

  • page: number
    The current page number (1-based).
  • onPageChange: (page: number) => void
    A callback invoked when the user navigates to another page; receives the new page number.
  • totalRecords: number | undefined
    The total number of records in the dataset (used to compute the number of pages).
  • recordsPerPage: number
    The number of records per page.
First name
Last name
Email
Birth date
JeraldHowellJerald.Howell32@yahoo.comMay 21 1950
KathleenRueckerKathleen_Ruecker@hotmail.comDec 19 1943
EricaVolkmanErica.Volkman37@gmail.comJan 29 1955
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comMar 6 1979
AlisonKlingAlison16@gmail.comJan 27 1997
SueZiemeSue.Zieme29@hotmail.comSep 12 1960
FeliciaGleasonFelicia30@yahoo.comMar 9 1977
AlfredoZemlakAlfredo22@yahoo.comNov 12 1988
EmilyBartolettiEmily.Bartoletti@gmail.comJan 5 1968
DeloresReynoldsDelores.Reynolds@yahoo.comJun 4 2004
LouisSchambergerLouis6@yahoo.comSep 7 1994
BeverlyHellerBeverly_Heller@gmail.comNov 29 2001
EugeneFeestEugene88@hotmail.comFeb 20 1954
MartinBahringerMartin_Bahringer10@gmail.comMay 26 1945
EllisMillerEllis36@hotmail.comMay 24 1950
1 - 15 / 500
No records

You can customize the default pagination behavior and appearance with the following optional properties:

  • loadingText: string
    The text displayed in the pagination footer while records are loading. Defaults to ....
  • noRecordsText: string
    The text displayed when there are no records. Defaults to No records. The same text is used by the empty state indicator.
  • paginationText
    A callback receiving an object in the shape of { from: number; to: number; totalRecords: number } and returning a ReactNode representing the pagination text. By default, the text looks like 1 - 15 / 500.
  • paginationSize: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
    The pagination size. Defaults to sm.
  • paginationWrapBreakpoint: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | (string & {}) | number
    A breakpoint below which the pagination footer content will wrap on multiple lines. Defaults to sm.
    You can also provide a string like '300px' or '20rem', or a number, which is interpreted as a pixel value and converted to rem.
  • paginationActiveTextColor: MantineColor | { light: MantineColor; dark: MantineColor }
    The text color of the active page button. Defaults to white.
  • paginationActiveBackgroundColor: MantineColor | { light: MantineColor; dark: MantineColor }
    The background color of the active page button. Defaults to the theme’s primary color.

Both color properties accept a MantineColor (a key of theme.colors or any valid CSS color string), or an object with light and dark keys, to use different colors for the light and dark color schemes.

Here is the code for the example above:

'use client';

import { DataTable } from 'mantine-datatable';
import dayjs from 'dayjs';
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 (
    <DataTable
      height={300}
      withTableBorder
      records={records}
      columns={[
        { accessor: 'firstName', width: 100 },
        { accessor: 'lastName', width: 100 },
        { accessor: 'email', width: '100%' },
        {
          accessor: 'birthDate',
          textAlign: '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 pagination size
      // paginationSize="md"
      // 👇 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 lines to use custom pagination colors
      // paginationActiveBackgroundColor="green"
      // paginationActiveTextColor="#e6e348"
    />
  );
}

Displaying a page size selector

To let the user choose the page size, set the following properties:

  • recordsPerPageOptions: number[]
    An array of page sizes to choose from.
  • onRecordsPerPageChange: (recordsPerPage: number) => void
    A callback invoked when the user selects another page size; receives the new page size.
  • recordsPerPageLabel: string
    The page size selector label. Defaults to 'Records per page'.
'use client';

import { DataTable } from 'mantine-datatable';
import dayjs from 'dayjs';
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]);
  const [page, setPage] = useState(1);
  const [records, setRecords] = useState(employees.slice(0, pageSize));

  // biome-ignore lint/correctness/useExhaustiveDependencies: reset page when pageSize changes
  useEffect(() => {
    setPage(1);
  }, [pageSize]);

  useEffect(() => {
    const from = (page - 1) * pageSize;
    const to = from + pageSize;
    setRecords(employees.slice(from, to));
  }, [page, pageSize]);

  return (
    <DataTable
      withTableBorder
      records={records}
      columns={[
        { accessor: 'firstName', width: 100 },
        { accessor: 'lastName', width: 100 },
        { accessor: 'email', width: '100%' },
        {
          accessor: 'birthDate',
          textAlign: 'right',
          width: 120,
          render: ({ birthDate }) => dayjs(birthDate).format('MMM D YYYY'),
        },
      ]}
      totalRecords={employees.length}
      paginationActiveBackgroundColor="grape"
      recordsPerPage={pageSize}
      page={page}
      onPageChange={(p) => setPage(p)}
      recordsPerPageOptions={PAGE_SIZES}
      onRecordsPerPageChange={setPageSize}
    />
  );
}
First name
Last name
Email
Birth date
JeraldHowellJerald.Howell32@yahoo.comMay 21 1950
KathleenRueckerKathleen_Ruecker@hotmail.comDec 19 1943
EricaVolkmanErica.Volkman37@gmail.comJan 29 1955
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comMar 6 1979
AlisonKlingAlison16@gmail.comJan 27 1997
SueZiemeSue.Zieme29@hotmail.comSep 12 1960
FeliciaGleasonFelicia30@yahoo.comMar 9 1977
AlfredoZemlakAlfredo22@yahoo.comNov 12 1988
EmilyBartolettiEmily.Bartoletti@gmail.comJan 5 1968
DeloresReynoldsDelores.Reynolds@yahoo.comJun 4 2004
LouisSchambergerLouis6@yahoo.comSep 7 1994
BeverlyHellerBeverly_Heller@gmail.comNov 29 2001
EugeneFeestEugene88@hotmail.comFeb 20 1954
MartinBahringerMartin_Bahringer10@gmail.comMay 26 1945
EllisMillerEllis36@hotmail.comMay 24 1950
1 - 15 / 500
Records per page
No records

Showing first and last page buttons

The pagination component shows “previous page” and “next page” buttons by default. Set paginationWithEdges to also show “first page” and “last page” buttons, or set paginationWithControls to false to hide the “previous” and “next” buttons:

<DataTable
  // other props...
  paginationWithEdges // 👈 show “first page” and “last page” buttons
  // 👇 uncomment the next line to hide the “previous page” and “next page” buttons
  // paginationWithControls={false}
/>
First name
Last name
Email
Birth date
JeraldHowellJerald.Howell32@yahoo.comMay 21 1950
KathleenRueckerKathleen_Ruecker@hotmail.comDec 19 1943
EricaVolkmanErica.Volkman37@gmail.comJan 29 1955
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comMar 6 1979
AlisonKlingAlison16@gmail.comJan 27 1997
SueZiemeSue.Zieme29@hotmail.comSep 12 1960
FeliciaGleasonFelicia30@yahoo.comMar 9 1977
AlfredoZemlakAlfredo22@yahoo.comNov 12 1988
EmilyBartolettiEmily.Bartoletti@gmail.comJan 5 1968
DeloresReynoldsDelores.Reynolds@yahoo.comJun 4 2004
1 - 10 / 500
No records

Customizing pagination controls

You can fully customize the pagination footer by providing a renderPagination callback. It receives a context object with the following keys:

  • state: the current pagination state (page, totalPages, totalRecords, recordsPerPage, from, to, fetching, paginationSize, isWrapped, etc.);
  • actions: setPage and, when the page size selector is enabled, setRecordsPerPage;
  • Controls: factories for the default controls — Controls.Text (the pagination text), Controls.PageSizeSelector (the page size selector, if enabled) and Controls.Pagination (the Mantine Pagination component). Each of them accepts optional props to override the defaults.

This allows you to render the controls in any order, inject your own elements, or override their props. The example below adds a “jump to page” input between the page size selector and the pagination component:

<DataTable
  // other props...
  // 👇 custom "Jump to page" control using renderPagination callback
  renderPagination={({ state, actions, Controls }) => (
    <>
      <Controls.Text />
      <Controls.PageSizeSelector />
      <Group gap="xs">
        <Text size={state.paginationSize}>Jump to page</Text>
        <NumberInput
          // 👇 custom input height to match pagination button height
          styles={{ wrapper: { '--input-height-sm': '26px' } }}
          hideControls
          w={80}
          size={state.paginationSize}
          onChange={(p) => typeof p === 'number' && actions.setPage(p)}
          min={1}
          max={max}
          value={page}
        />
      </Group>
      <Controls.Pagination />
    </>
  )}
/>
First name
Last name
Email
Birth date
JeraldHowellJerald.Howell32@yahoo.comMay 21 1950
KathleenRueckerKathleen_Ruecker@hotmail.comDec 19 1943
EricaVolkmanErica.Volkman37@gmail.comJan 29 1955
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comMar 6 1979
AlisonKlingAlison16@gmail.comJan 27 1997
SueZiemeSue.Zieme29@hotmail.comSep 12 1960
FeliciaGleasonFelicia30@yahoo.comMar 9 1977
AlfredoZemlakAlfredo22@yahoo.comNov 12 1988
EmilyBartolettiEmily.Bartoletti@gmail.comJan 5 1968
DeloresReynoldsDelores.Reynolds@yahoo.comJun 4 2004
LouisSchambergerLouis6@yahoo.comSep 7 1994
BeverlyHellerBeverly_Heller@gmail.comNov 29 2001
EugeneFeestEugene88@hotmail.comFeb 20 1954
MartinBahringerMartin_Bahringer10@gmail.comMay 26 1945
EllisMillerEllis36@hotmail.comMay 24 1950
1 - 15 / 500
Records per page

Jump to page

No records

Passing props to pagination buttons

You can pass additional props to the pagination buttons with these callbacks:

  • getPaginationControlProps: receives the control type ('first', 'last', 'previous' or 'next') and returns an object of props for that control;
  • getPaginationItemProps: receives a page number and returns an object of props for the corresponding page button.

For instance, if you’re not happy with the default accessibility 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 {};
  }}
  getPaginationItemProps={(pageNumber) => {
    const title = `Go to page ${pageNumber}`;
    return { title, 'aria-label': title };
  }}
/>
First name
Last name
Email
Birth date
JeraldHowellJerald.Howell32@yahoo.comMay 21 1950
KathleenRueckerKathleen_Ruecker@hotmail.comDec 19 1943
EricaVolkmanErica.Volkman37@gmail.comJan 29 1955
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comMar 6 1979
AlisonKlingAlison16@gmail.comJan 27 1997
SueZiemeSue.Zieme29@hotmail.comSep 12 1960
FeliciaGleasonFelicia30@yahoo.comMar 9 1977
AlfredoZemlakAlfredo22@yahoo.comNov 12 1988
EmilyBartolettiEmily.Bartoletti@gmail.comJan 5 1968
DeloresReynoldsDelores.Reynolds@yahoo.comJun 4 2004
LouisSchambergerLouis6@yahoo.comSep 7 1994
BeverlyHellerBeverly_Heller@gmail.comNov 29 2001
EugeneFeestEugene88@hotmail.comFeb 20 1954
MartinBahringerMartin_Bahringer10@gmail.comMay 26 1945
EllisMillerEllis36@hotmail.comMay 24 1950
1 - 15 / 500
No records

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by