Pagination

DataGrid pagination features

Basic pagination

Pass pageSize to useDataGrid to split data into pages, 10 rows per page by default. Add DataGrid.Footer as a child of DataGrid to display the status text, the page size select and the page buttons:

First Name
Last Name
Email
Department
Salary
AliceJohnsonalice.johnson@example.comEngineering95000
BobSmithbob.smith@example.comMarketing72000
CarolWilliamscarol.williams@example.comSales68000
DavidBrowndavid.brown@example.comHR65000
EvaDaviseva.davis@example.comFinance88000
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'email', header: 'Email', size: 220 },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary' },
    ],
    pageSize: 5,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Footer />
    </DataGrid>
  );
}

Status formats

By default, the status text is 1–10 of 20. Set statusFormat="long" to display Showing 1–10 of 20 instead. The number of selected rows is added while rows are selected:

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
import { useState } from 'react';
import { SegmentedControl } from '@mantine/core';
import { DataGrid, DataGridFooterProps, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [statusFormat, setStatusFormat] = useState<DataGridFooterProps['statusFormat']>('compact');

  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
    pageSize: 5,
  });

  return (
    <>
      <SegmentedControl
        size="xs"
        mb="md"
        data={['compact', 'long']}
        value={statusFormat}
        onChange={(value) => setStatusFormat(value as DataGridFooterProps['statusFormat'])}
      />
      <DataGrid store={store}>
        <DataGrid.Footer statusFormat={statusFormat} />
      </DataGrid>
    </>
  );
}

Arrows

Set pagination="arrows" to replace the page buttons with a Page 1 of 2 label and previous / next controls:

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    pageSize: 5,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Footer pagination="arrows" />
    </DataGrid>
  );
}

Compact layout

In a narrow grid, the footer hides the page size select and replaces the page buttons with a Page 1 of 2 label. The breakpoint depends on the grid size and statusFormat. Resize the demo to see it:

First Name
Department
AliceEngineering
BobMarketing
CarolSales
import { Box } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'department', header: 'Department' },
    ],
    getRowId: (row) => row.id,
    pageSize: 3,
  });

  return (
    <Box style={{ resize: 'horizontal', overflow: 'auto', minWidth: 320, maxWidth: '100%' }}>
      <DataGrid store={store}>
        <DataGrid.Footer pageSizeOptions={[3, 6, 9]} />
      </DataGrid>
    </Box>
  );
}

Status only

Set pagination="none" to display the status text only:

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
FrankMillerEngineering102000
GraceWilsonMarketing76000
HenryTaylorSales71000
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees.slice(0, 8),
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    getRowId: (row) => row.id,
    withRowSelection: true,
  });

  return (
    <DataGrid store={store}>
      <DataGrid.Footer pagination="none" statusFormat="long" />
    </DataGrid>
  );
}

Page size

Use pageSizeOptions to change the options of the page size select, [10, 25, 50, 100] by default. Set withPageSize={false} to hide the select, use selectProps to pass props to it:

<DataGrid store={store}>
  <DataGrid.Footer pageSizeOptions={[5, 10, 25]} selectProps={{ w: 130 }} />
</DataGrid>

paginationProps are passed down to the Pagination component.

One page

When all rows fit on one page, the footer hides the page buttons. The page size select stays while a smaller page size would add pages. Set hideWithOnePage={false} on DataGrid.Footer to keep the page buttons:

<DataGrid store={store}>
  <DataGrid.Footer hideWithOnePage={false} />
</DataGrid>

Controlled pagination

Pass pagination and onPaginationChange to useDataGrid to control pagination state. The state is an object with pageIndex and pageSize:

Current page: {"pageIndex":0,"pageSize":5}

First Name
Last Name
Department
Salary
Status
AliceJohnsonEngineering95000active
BobSmithMarketing72000active
CarolWilliamsSales68000active
DavidBrownHR65000inactive
EvaDavisFinance88000active
import { useState } from 'react';
import { PaginationState } from '@tanstack/react-table';
import { Code, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const [pagination, setPagination] = useState<PaginationState>({
    pageIndex: 0,
    pageSize: 5,
  });

  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary' },
      { accessorKey: 'status', header: 'Status' },
    ],
    pagination,
    onPaginationChange: setPagination,
  });

  return (
    <>
      <Text mb="md">
        Current page: <Code>{JSON.stringify(pagination)}</Code>
      </Text>
      <DataGrid store={store}>
        <DataGrid.Footer />
      </DataGrid>
    </>
  );
}

Custom footer

Pass children to DataGrid.Footer to replace the default controls with your own. Use store.getPagination(), store.table.getRowCount() and the navigation methods below to build them. A footer built without DataGrid.Footer must set the --dg-footer-height CSS variable for the floating selection bar to stay above it:

First Name
Last Name
Department
Salary
AliceJohnsonEngineering95000
BobSmithMarketing72000
CarolWilliamsSales68000
DavidBrownHR65000
EvaDavisFinance88000
import { Button, Group, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';

function Demo() {
  const store = useDataGrid({
    data: employees,
    columns: [
      { accessorKey: 'firstName', header: 'First Name' },
      { accessorKey: 'lastName', header: 'Last Name' },
      { accessorKey: 'department', header: 'Department' },
      { accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
    ],
    pageSize: 5,
  });

  const { pageIndex, pageSize } = store.getPagination();
  const total = store.table.getRowCount();

  return (
    <DataGrid store={store}>
      <DataGrid.Footer>
        <Text size="sm">
          Employees {pageIndex * pageSize + 1}–{Math.min((pageIndex + 1) * pageSize, total)} of{' '}
          {total}
        </Text>
        <Group gap="xs" ml="auto">
          <Button
            size={store.getControlSize()}
            variant="default"
            disabled={!store.table.getCanPreviousPage()}
            onClick={() => store.table.previousPage()}
          >
            Previous
          </Button>
          <Button
            size={store.getControlSize()}
            variant="default"
            disabled={!store.table.getCanNextPage()}
            onClick={() => store.table.nextPage()}
          >
            Next
          </Button>
        </Group>
      </DataGrid.Footer>
    </DataGrid>
  );
}

Page navigation methods

Use store.table methods to change the page programmatically:

store.table.firstPage();
store.table.previousPage();
store.table.nextPage();
store.table.lastPage();
store.table.setPageIndex(2);
store.table.setPageSize(25);
store.table.getCanPreviousPage();
store.table.getCanNextPage();
store.table.getPageCount();
store.table.getRowCount();

Auto-reset page index

By default, the page index resets to 0 when data, sorting or filtering changes. Pass autoResetPageIndex: false to useDataGrid to keep the current page:

const store = useDataGrid({
  data,
  columns,
  autoResetPageIndex: false,
});

Server-side pagination

Set manualPagination and provide rowCount with the total number of rows, or pageCount if you only know the number of pages:

const store = useDataGrid({
  data: serverData,
  columns,
  manualPagination: true,
  pagination,
  onPaginationChange,
  rowCount: totalRows,
});

Without rowCount and pageCount, the footer displays Page 3 with previous / next controls. See the Server-side page for a complete example.

Labels

Use labels prop of DataGrid to translate the footer texts:

  • footerRange – {from}–{to} of {total}
  • footerRangeLong – Showing {from}–{to} of {total}
  • footerRows – {count} rows
  • footerRowsOne – {count} row
  • footerSelected – {count} selected
  • footerPage – Page {page} of {total}
  • footerPageUnknownTotal – Page {page}
  • pageSize – {count} / page
  • pageSizeLabel – Rows per page
  • paginationPrevious – Previous page
  • paginationNext – Next page