Material-table: Changing the header background color, font size and font color

Created on 11 Feb 2019  路  11Comments  路  Source: mbrn/material-table

How can I change the header background color, font size and font color?

help wanted

Most helpful comment

Hi, do you know how to change the color of the title of the table?
title={this.props.title}
/>

All 11 comments

Add a header style on your column definition that you want to style:
{ title: '...', field: '...', headerStyle: {backgroundColor: 'red'}}

If you want to apply a style to all columns just add a header style to options.

Thanks! It works when adding the headerstyle per column.

I want to apply the style to all columns. It seems not working.

columns={[
{
title: 'Name',
render: rowData => rowData.name + ' ' + rowData.surname,
},
{ title: 'Birth Year', field: 'birthYear', type: 'numeric' },
{
title: 'Birth Place',
field: 'birthCity',
lookup: { 34: '陌stanbul', 63: '艦anl谋urfa' },
},
{
title: 'Score',
field: 'successScore',
render: rowData => {
const score = rowData.successScore + '%'
const color = rowData.successScore > 70 ? '#4CAF50' : '#f44336'
return (

style={{
textAlign: 'left',
padding: 1,
color: 'white',
width: score,
backgroundColor: color,
height: 20,
}}
>
{score}


)
},
},
]}
data={[
{
name: 'Mehmet',
surname: 'Baran',
birthYear: 1987,
birthCity: 63,
successScore: 58,
},
{
name: 'Zerya Bet眉l',
surname: 'Baran',
birthYear: 2017,
birthCity: 34,
successScore: 90,
},
]}
title="Custom Render"
headerStyle={{backgroundcolor:'red'}}
/>

Use this:

<MaterialTable
...
options={{
headerStyle:{backgroundColor:'red'}
}}
/>

Thanks @mbrn!

Hi, do you know how to change the color of the title of the table?
title={this.props.title}
/>

Hi, how to change the color of the icon?

Hi @mbrn, how i can change the background of the table?

Hi, do you know how to change the color of the title of the table?

Hi @betocolon23,
I did it using MuiThemeProvider to override default styling, as MuiTypography-h6 component is being used for the table title.

const theme = createMuiTheme({
  overrides: {
    MuiTypography: {
      h6: {
        fontWeight: 'bolder !important',
        color: darken('#5CDB94', 0.15),
      },
    },
  },
});

<ThemeProvider theme={theme}>
  <MaterialTable
    ...
  />
</ThemeProvider>

other solution is component overriding

import MaterialTable, { MTableToolbar } from 'material-table';

<MaterialTable
    components={{
      Toolbar: props => (
        <div style={{color: darken('#5CDB94', 0.15),}}>
           <MTableToolbar {...props} />
        </div>
       )
    }}
/>

Great!! Thanks

Is there any way to access MUI theme palette colors directly in the headerStyle prop? I want to set header color="primary". Would I need a custom override for this?

@alexanderkho here is how I did it:

import { makeStyles, useTheme } from "@material-ui/core/styles";
const theme = useTheme()

<MaterialTable
          headerStyle: {
            width: 26,
            whiteSpace: 'nowrap',
            textAlign: 'left',
            flexDirection: 'row',
            overflow: 'hidden',
            textOverflow: 'ellipsis',
            paddingLeft: 5,
            paddingRight: 5,
            backgroundColor: theme.palette.primary.table,
            fontWeight: 'bold',
            color: theme.palette.primary.main,
          },
/>
Was this page helpful?
0 / 5 - 0 ratings