Examples › Row styling

You can style individual rows based on their data using the rowColor, rowBackgroundColor, rowClassName and rowStyle properties.
They are the row-level counterparts of the c, backgroundColor, className and style properties of the DataTable component, but they accept functions that receive the current record and its index, so each row can be styled differently (rowClassName also accepts a plain string).

Using rowColor and rowBackgroundColor

The rowColor and rowBackgroundColor properties accept a function that receives the current record and its index as arguments and returns either a MantineColor (a key of theme.colors or any valid CSS color string) to be applied to the row, or an object with light and dark keys and MantineColor values to be applied in light and dark color schemes respectively. Return undefined to leave a row with its default colors.

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 used to produce the result above:

return (
  <DataTable
    rowColor={({ state }) => {
      if (state === 'MA') return 'violet';
    }}
    rowBackgroundColor={({ state }) => {
      if (state === 'MA') return { dark: '#232b25', light: '#f0f7f1' };
    }}
    // other table props...
  />
);

Using rowClassName

The rowClassName property accepts either a string, to apply the same class name to every row, or a function that receives the current record and its index as arguments and returns the class name to be applied to the row (or undefined for no extra class).

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 used to produce the result above:

return (
  <DataTable
    rowClassName={({ state }) => (state === 'WY' ? classes.redRow : undefined)}
    // other table props...
  />
);

Using rowStyle

The rowStyle property accepts a function that receives the current record and its index as arguments and returns either a style object to be applied to the row, or a function that accepts the current theme and returns such an 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 used to produce the result above:

return (
  <DataTable
    rowStyle={({ state }) => (state === 'NH' ? { fontStyle: 'italic', fontWeight: 'bold' } : undefined)}
    // other table props...
  />
);

And here is how you could build the style based on the current theme, by returning a function:

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 used to produce the result above:

return (
  <DataTable
    rowStyle={({ state }) =>
      (theme) => ({ color: state === 'MA' ? theme.colors.violet[6] : theme.colors.gray[6] })}
    // other table props...
  />
);

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by