Examples › Overriding the default styles

Mantine DataTable closely follows the current Mantine theme, so it should look great out of the box in most cases.

However, if you’re not happy with the default Mantine DataTable styling, there are several ways to override it.

With color properties

You can quickly customize the default colors using the c, backgroundColor, borderColor and rowBorderColor properties.
Each of these properties can be set to a MantineColor (key of theme.colors or any valid CSS color string) or an object with dark and light keys and MantineColor values, which will be used to style dark and light themes accordingly.

The c property refers to the text color and is applied to:

  • the table body, header and footer;
  • the pagination component (if present).

The backgroundColor is applied to:

  • the table body, header and footer;
  • the pagination component (if present).

The borderColor is applied to:

The rowBorderColor is applied to:

If you’re using pagination, you can also customize its colors using the paginationTextColor and paginationActiveTextColor properties.

For example, this code:

return (
  <DataTable
    withTableBorder
    withColumnBorders
    // 👇 override default text color for light and dark themes
    c={{ dark: '#dbc7a0', light: '#55350d' }}
    // 👇 override default background color for light and dark themes
    backgroundColor={{ dark: '#232b25', light: '#f0f7f1' }}
    borderColor="#40c057" // 👈 override default border color
    rowBorderColor="#fab005" // 👈 override default row border color
    paginationActiveBackgroundColor="#40c057" // 👈 override default pagination active background color
    // ...
  />
);

…will produce the following table:

Name
Street address
City
State
Connelly, Feest and Hodkiewicz7057 Stanley RoadKearaburghCA
Cummerata - Kuhlman6389 Dicki StreamSouth GateNH
Doyle, Hodkiewicz and O'Connell576 Joyce WaysTyraburghKS
Feest, Bogan and Herzog21716 Ratke DriveStromanportWY
13 companies12 cities7 states
1 - 4 / 13
No records

There are even more elaborate ways to destroy the default styling of Mantine DataTable besides setting its basic properties and the aforementioned colors.

With className

You can specify a className that will target the DataTable component root:

Name
Mission statement
Street address
City
State
Feest, Bogan and HerzogInnovate bricks-and-clicks metrics.21716 Ratke DriveStromanportWY
Cummerata - KuhlmanHarness real-time channels.6389 Dicki StreamSouth GateNH
Goyette IncProductize front-end web services.8873 Mertz RapidDorthysideID
Runte IncEngage synergistic infrastructures.2996 Ronny MountMcAllenMA
Goldner, Rohan and LehnerIncubate cross-platform metrics.632 Broadway AvenueNorth LouieWY
No records

Here is the code for the above example:

import { DataTable } from 'mantine-datatable';
import classes from './StylingWithClassNameExample.module.css';
// ...

export function StylingWithClassNameExample() {
  return (
    <DataTable
      className={classes.root}
      // ...
    />
  );
}

With a style object or function

You can target the DataTable component root with a style object:

Name
Mission statement
Street address
City
State
Feest, Bogan and HerzogInnovate bricks-and-clicks metrics.21716 Ratke DriveStromanportWY
Cummerata - KuhlmanHarness real-time channels.6389 Dicki StreamSouth GateNH
Goyette IncProductize front-end web services.8873 Mertz RapidDorthysideID
Runte IncEngage synergistic infrastructures.2996 Ronny MountMcAllenMA
Goldner, Rohan and LehnerIncubate cross-platform metrics.632 Broadway AvenueNorth LouieWY
No records

Here is the code for the above example:

return (
  <DataTable
    style={{
      border: '1px solid #40C057',
      fontStyle: 'italic',
    }}
    // ...
  />
);

The style property also accepts a function that receives the current theme as argument and returns a style object:

Name
Mission statement
Street address
City
State
Feest, Bogan and HerzogInnovate bricks-and-clicks metrics.21716 Ratke DriveStromanportWY
Cummerata - KuhlmanHarness real-time channels.6389 Dicki StreamSouth GateNH
Goyette IncProductize front-end web services.8873 Mertz RapidDorthysideID
Runte IncEngage synergistic infrastructures.2996 Ronny MountMcAllenMA
Goldner, Rohan and LehnerIncubate cross-platform metrics.632 Broadway AvenueNorth LouieWY
No records

Here is the code for the above example:

return (
  <DataTable
    style={(theme) => ({
      border: `1px solid ${theme.colors.indigo[6]}`,
      borderRadius: theme.radius.md,
      color: theme.colors.violet[6],
    })}
    // ...
  />
);

With multiple class names

You can specifically target the component root, table, header, footer and pagination with different classNames:

Name
Mission statement
Street address
City
State
Feest, Bogan and HerzogInnovate bricks-and-clicks metrics.21716 Ratke DriveStromanportWY
Cummerata - KuhlmanHarness real-time channels.6389 Dicki StreamSouth GateNH
Goyette IncProductize front-end web services.8873 Mertz RapidDorthysideID
Runte IncEngage synergistic infrastructures.2996 Ronny MountMcAllenMA
13 companiesAvg. chars: 31.230769230769237 states
1 - 4 / 13
No records

Here is the code for the above example:

return (
  <DataTable
    withColumnBorders
    classNames={{
      root: classes.root,
      table: classes.table,
      header: classes.header,
      footer: classes.footer,
      pagination: classes.pagination,
    }}
    // ...
  />
);

With multiple style objects or functions

You can specifically target the component root, table, header, footer and pagination with different styles objects or functions:

Name
Mission statement
Street address
City
State
Feest, Bogan and HerzogInnovate bricks-and-clicks metrics.21716 Ratke DriveStromanportWY
Cummerata - KuhlmanHarness real-time channels.6389 Dicki StreamSouth GateNH
Goyette IncProductize front-end web services.8873 Mertz RapidDorthysideID
Runte IncEngage synergistic infrastructures.2996 Ronny MountMcAllenMA
Goldner, Rohan and LehnerIncubate cross-platform metrics.632 Broadway AvenueNorth LouieWY
No records

Here is the code for the above example:

return (
  <DataTable
    styles={{
      // 👇 this is a function that receives the current theme as argument
      root: (theme) => ({
        border: `1px solid ${theme.colors.orange[6]}`,
      }),
      table: {
        color: '#666',
      },
      header: {
        color: '#A30',
        fontSize: '125%',
      },
    }}
    // ...
  />
);

Head over to the next example to discover more features.