Examples › Column properties and styling

The accessor

The only property you have to specify for a column is its accessor — the name of the record property whose value you want to display in the column cells.
The accessor supports dot-notation for drilling into nested objects (e.g. 'department.company.name').
The component derives a column header title by “humanizing” the accessor (e.g. 'firstName' → 'First name' or 'department.company.name' → 'Department company name').
If you’re not happy with the automatically derived title, you can override it by setting your own column title, which can be any ReactNode.

Basic column properties

Each column can be further customized by specifying the following properties:

  • width: number | string
    Desired column width.
  • ellipsis: boolean
    If true, cell content in this column will not wrap to multiple lines and will be truncated with an ellipsis if needed.
    You can set either this property or noWrap, but not both.
  • noWrap: boolean
    If true, cell content in this column will not wrap to multiple lines (i.e. white-space: nowrap).
    You can set either this property or ellipsis, but not both.
  • textAlign: 'left' | 'center' | 'right'
    Text alignment of the column title, cells and footer. Defaults to 'left' if not specified.
  • hidden: boolean
    If true, the column will not be visible.
  • visibleMediaQuery
    A media query string, or a function accepting the current MantineTheme as its argument and returning a media query string.
    If set, the column will only be visible when the media query matches.
  • render
    A function that accepts the current record and its index in records as arguments and returns a ReactNode (keep in mind that strings and numbers are valid React nodes).
  • filter
    An optional property which provides the user with filtering options. It can be either a ReactNode or a function returning a ReactNode.
    If set, a filter button will be added to the column header. Clicking the button opens a popover showing the provided node.
    If you provide a function, it will be called with an object containing a close() method, which you can call to close the popover.
  • filtering: boolean
    If true, the filter button in the column header will be highlighted to indicate that a filter is in effect. Defaults to false if not specified.
  • filterPopoverProps
    Props passed to the filter Popover, in case you need to override its defaults (position, width, shadow, etc.).
  • filterPopoverDisableClickOutside: boolean
    If true, disables the click-outside handler the DataTable attaches to the filter popover dropdown. Combine it with filterPopoverProps={{ closeOnClickOutside: false }} to keep the popover open until it’s closed explicitly, which is useful when the filter contains components rendering their own dropdowns in a portal, such as date pickers or selects.
  • filterButtonLabel: string
    Accessible label (aria-label) of the filter button in the column header. Defaults to Filter <column title> when the column title is a string, or to Filter otherwise; set it to localize the label or to describe the filter more precisely.

You can create a “virtual column” by providing an accessor that doesn’t refer to an existing property (or nested property) of the records. In this case, you must provide a custom render function. Also, keep in mind that each accessor must be unique within the columns collection.

Consider this example:

#
Full name
Email
Department name
Company
Birthday
Age
1Jerald HowellJerald.Howell32@yahoo.comIndustrialRunte IncMay 2176
2Kathleen RueckerKathleen_Ruecker@hotmail.comComputersShanahan, Robel and BeierDec 1982
3Erica VolkmanErica.Volkman37@gmail.comToysGoyette IncJan 2971
4Clifford OberbrunnerClifford.Oberbrunner@hotmail.comAutomotiveRau - O'HaraMar 647
5Alison KlingAlison16@gmail.comJeweleryGoyette IncJan 2729
6Sue ZiemeSue.Zieme29@hotmail.comBooksCummerata - KuhlmanSep 1266
7Felicia GleasonFelicia30@yahoo.comShoesDoyle, Hodkiewicz and O'ConnellMar 949
8Alfredo ZemlakAlfredo22@yahoo.comGamesRunte IncNov 1238
9Emily BartolettiEmily.Bartoletti@gmail.comAutomotiveRau - O'HaraJan 558
10Delores ReynoldsDelores.Reynolds@yahoo.comIndustrialRunte IncJun 422
No records

Here’s the code for the example above:

'use client';

import { DataTable } from 'mantine-datatable';
import dayjs from 'dayjs';
import { employees } from '~/data';

const records = employees.slice(0, 10);

export function ColumnPropertiesExample() {
  return (
    <DataTable
      withTableBorder
      withColumnBorders
      striped
      records={records}
      columns={[
        {
          accessor: 'index',
          title: '#',
          textAlign: 'right',
          width: 40,
          // 👇 `render` receives the record and its index in `records`
          render: (_, index) => index + 1,
        },
        {
          accessor: 'name',
          title: 'Full name',
          render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
          width: 160,
        },
        { accessor: 'email' },
        { accessor: 'department.name', width: 150 },
        {
          // 👇 using dot-notation to access nested object property
          accessor: 'department.company.name',
          title: 'Company',
          width: 150,
          // 👇 truncate with ellipsis if text overflows the available width
          ellipsis: true,
        },
        {
          accessor: 'birthDate',
          title: 'Birthday',
          width: 100,
          render: ({ birthDate }) => dayjs(birthDate).format('MMM D'),
          // 👇 column is only visible when screen width is over `theme.breakpoints.xs`
          visibleMediaQuery: (theme) => `(min-width: ${theme.breakpoints.xs})`,
        },
        {
          // 👇 "virtual column"
          accessor: 'age',
          width: 60,
          textAlign: 'right',
          // 👇 column is only visible when screen width is over `theme.breakpoints.xs`
          visibleMediaQuery: (theme) => `(min-width: ${theme.breakpoints.xs})`,
          render: ({ birthDate }) => dayjs().diff(birthDate, 'years'),
        },
      ]}
    />
  );
}

Column footers

The DataTable component will display a footer row at the bottom of the table if you specify a footer property for at least one column:

Full name
Department name
Company
Age
Jerald HowellIndustrialRunte Inc76
Kathleen RueckerComputersShanahan, Robel and Beier82
Erica VolkmanToysGoyette Inc71
Clifford OberbrunnerAutomotiveRau - O'Hara47
Alison KlingJeweleryGoyette Inc29
Sue ZiemeBooksCummerata - Kuhlman66
Felicia GleasonShoesDoyle, Hodkiewicz and O'Connell49
Alfredo ZemlakGamesRunte Inc38
Emily BartolettiAutomotiveRau - O'Hara58
Delores ReynoldsIndustrialRunte Inc22
10 employees
6 companies
Avg: 54
No records

Here’s the code for the example above:

<DataTable
  withTableBorder
  withColumnBorders
  striped
  records={records}
  height={height}
  withRowBorders
  columns={[
    {
      accessor: 'name',
      title: 'Full name',
      render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
      width: 160,
      // 👇 this column has a footer
      footer: (
        <Group gap="xs">
          <Box mb={-4}>
            <IconSum size="1.25em" />
          </Box>
          <div>{records.length} employees</div>
        </Group>
      ),
    },
    // 👇 this column has NO footer
    { accessor: 'department.name', width: 150 },
    {
      accessor: 'department.company.name',
      title: 'Company',
      width: 150,
      ellipsis: true,
      // 👇 this column has a footer
      footer: (
        <Group gap="xs">
          <Box mb={-4}>
            <IconSum size={16} />
          </Box>
          <div>{uniqBy(records, (record) => record.department.company.name).length} companies</div>
        </Group>
      ),
    },
    {
      accessor: 'age',
      width: 60,
      textAlign: 'right',
      visibleMediaQuery: (theme) => `(min-width: ${theme.breakpoints.xs})`,
      render: ({ birthDate }) => dayjs().diff(birthDate, 'years'),
      // 👇 this column has a footer
      footer: `Avg: ${Math.round(
        records.map((record) => dayjs().diff(record.birthDate, 'years')).reduce((a, b) => a + b, 0) / records.length
      )}`,
    },
  ]}
/>

The footer is always visible and sticks to the bottom of the table. For example, if the table is scrollable:

Full name
Department name
Company
Age
Jerald HowellIndustrialRunte Inc76
Kathleen RueckerComputersShanahan, Robel and Beier82
Erica VolkmanToysGoyette Inc71
Clifford OberbrunnerAutomotiveRau - O'Hara47
Alison KlingJeweleryGoyette Inc29
Sue ZiemeBooksCummerata - Kuhlman66
Felicia GleasonShoesDoyle, Hodkiewicz and O'Connell49
Alfredo ZemlakGamesRunte Inc38
Emily BartolettiAutomotiveRau - O'Hara58
Delores ReynoldsIndustrialRunte Inc22
10 employees
6 companies
Avg: 54
No records

Or if the table is taller than its content:

Full name
Department name
Company
Age
Jerald HowellIndustrialRunte Inc76
Kathleen RueckerComputersShanahan, Robel and Beier82
Erica VolkmanToysGoyette Inc71
Clifford OberbrunnerAutomotiveRau - O'Hara47
Alison KlingJeweleryGoyette Inc29
Sue ZiemeBooksCummerata - Kuhlman66
Felicia GleasonShoesDoyle, Hodkiewicz and O'Connell49
Alfredo ZemlakGamesRunte Inc38
Emily BartolettiAutomotiveRau - O'Hara58
Delores ReynoldsIndustrialRunte Inc22
10 employees
6 companies
Avg: 54
No records

Styling column titles, cells and footers

You can customize the look of each column by specifying the following styling properties:

  • titleClassName: string
    A custom class name for the column title.
  • titleStyle
    A custom style object for the column title, or a function accepting the current theme and returning a style object.
  • cellsClassName
    A custom class name for the column cells, or a function that accepts the current record and its index as arguments and returns a class name.
  • cellsStyle
    A function that accepts the current record and its index as arguments and returns either a style object for the column cells, or a function accepting the current theme and returning a style object.
  • footerClassName: string
    A custom class name for the column footer.
  • footerStyle
    A custom style object for the column footer, or a function accepting the current theme and returning a style object.

Consider this example:

#
Full name
Email
Department name
Company
Birthday
Age
1Jerald HowellJerald.Howell32@yahoo.comIndustrialRunte IncMay 2176
2Kathleen RueckerKathleen_Ruecker@hotmail.comComputersShanahan, Robel and BeierDec 1982
3Erica VolkmanErica.Volkman37@gmail.comToysGoyette IncJan 2971
4Clifford OberbrunnerClifford.Oberbrunner@hotmail.comAutomotiveRau - O'HaraMar 647
5Alison KlingAlison16@gmail.comJeweleryGoyette IncJan 2729
6Sue ZiemeSue.Zieme29@hotmail.comBooksCummerata - KuhlmanSep 1266
7Felicia GleasonFelicia30@yahoo.comShoesDoyle, Hodkiewicz and O'ConnellMar 949
8Alfredo ZemlakAlfredo22@yahoo.comGamesRunte IncNov 1238
9Emily BartolettiEmily.Bartoletti@gmail.comAutomotiveRau - O'HaraJan 558
10Delores ReynoldsDelores.Reynolds@yahoo.comIndustrialRunte IncJun 422
10 employees6 companiesAvg: 54
No records

Here’s the code for the example above:

'use client';

import { DataTable, uniqBy } from 'mantine-datatable';
import { rgba } from '@mantine/core';
import clsx from 'clsx';
import dayjs from 'dayjs';
import { employees } from '~/data';
import classes from './ColumnStylingExample.module.css';

const records = employees.slice(0, 10);

export function ColumnStylingExample() {
  return (
    <DataTable
      withTableBorder
      withColumnBorders
      striped
      records={records}
      columns={[
        {
          accessor: 'index',
          title: '#',
          textAlign: 'right',
          width: 40,
          // 👇 style cells with a class name
          cellsClassName: classes.idColumnCells,
          render: (_, index) => index + 1,
        },
        {
          accessor: 'name',
          title: 'Full name',
          width: 160,
          // 👇 style cells with a function returning a style object
          //    this function receives the current record as its argument, but we're not using it here
          cellsStyle: () => ({ fontStyle: 'italic' }),
          // 👇 style cells with a class name depending on current record
          cellsClassName: ({ sex }) => clsx({ [classes.male]: sex === 'male', [classes.female]: sex === 'female' }),
          footer: `${records.length} employees`,
          // style footer with a style object
          footerStyle: { fontStyle: 'italic' },
          render: ({ firstName, lastName }) => `${firstName} ${lastName}`,
        },
        { accessor: 'email' },
        {
          accessor: 'department.name',
          width: 150,
          // 👇 style title with a function returning a style object
          titleStyle: (theme) => ({ color: theme.colors.green[6] }),
          // 👇 style cells with a function returning a style function
          cellsStyle: () => (theme) => ({
            color: theme.colors.green[8],
            background: rgba(theme.colors.orange[6], 0.25),
          }),
        },
        {
          accessor: 'department.company.name',
          title: 'Company',
          width: 150,
          ellipsis: true,
          footer: `${uniqBy(records, (record) => record.department.company.name).length} companies`,
          // 👇 style footer with a function returning a style object
          footerStyle: (theme) => ({ color: theme.colors.blue[6] }),
        },
        {
          accessor: 'birthDate',
          title: 'Birthday',
          width: 100,
          // 👇 style title with a custom class name
          titleClassName: classes.birthdayColumnTitle,
          // 👇 style cells with a function accepting the current record and returning another
          //    function that accepts the current theme and returns a style object
          //    (i.e. people born in winter will have their birthday in blue)
          cellsStyle:
            ({ birthDate }) =>
            (theme) => ({
              color: ['Dec', 'Jan', 'Feb'].includes(dayjs(birthDate).format('MMM')) ? theme.colors.blue[6] : undefined,
            }),
          render: ({ birthDate }) => dayjs(birthDate).format('MMM D'),
        },
        {
          accessor: 'age',
          width: 80,
          textAlign: 'right',
          // 👇 style title with a style object
          titleStyle: { fontStyle: 'italic' },
          // 👇 style cells depending on current record, with a function returning a style object
          cellsStyle: ({ birthDate }) =>
            dayjs().diff(birthDate, 'years') <= 40
              ? {
                  fontWeight: 'bold',
                  color: 'green',
                  background: '#FF332222',
                }
              : undefined,
          render: ({ birthDate }) => dayjs().diff(birthDate, 'years'),
          footer: `Avg: ${Math.round(
            records.map((record) => dayjs().diff(record.birthDate, 'years')).reduce((a, b) => a + b, 0) / records.length
          )}`,
          footerClassName: classes.ageFooter,
        },
      ]}
    />
  );
}

Other column properties

Column definitions accept a few more properties, each covered in detail by a dedicated example:

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by