1

I'm trying to change the head of mui-datatables, but it is not working properly.

import MUIDataTable from "mui-datatables";
import { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
...

// here I set the them
const getMuiTheme = () => createMuiTheme({
    overrides: {
        MuiTableHead: {
            root: {
                backgroundColor: "#c1e1ec"
            }
        }
    }
});

...

// rendering
<MuiThemeProvider theme={getMuiTheme()}>                                                    
    <MUIDataTable
        title={"Existing Users"}
        data={users}
        columns={columns}
        options={options}
    />
</MuiThemeProvider>

It is not changing the color of the thead. It keep showing a white thead. However, if I inspect the element with Firefox, I can see the following styles for the thead element

.MuiTableHead-root {
    display: table-header-group;
    background-color: #c1e1ec;
}

4 Answers 4

6

Each child .MUIDataTableHeadCell-fixedHeader has own background so you rather should change this class then .MuiTableHeader-root

Or in this way which I think is better.

MuiTableCell: {
    head: {
        backgroundColor: "red !important"
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Does this code work in functional components?
0

I found below codes works for me

MUIDataTableHeadCell: {
  styleOverrides: {
    fixedHeader: { backgroundColor: "transparent" },
  },
},

It's reply from https://github.com/gregnb/mui-datatables/issues/162

Comments

0
  MUIDataTableHeadCell: {
    styleOverrides:{
      root: {
          backgroundColor: "red"
      }
    }
  },
  MUIDataTableBodyCell: {
    styleOverrides:{
      root: {
          backgroundColor: "yellow"
      }
    }
  },
  MuiTableFooter: {
    styleOverrides:{
      root: {
          backgroundColor: "wheat"
      }
    }
  },
  MuiToolbar: {
    styleOverrides:{
      root: {
          backgroundColor: "teal"
      }
    }
  }      
}

Comments

0

This is the only solution that worked for me

 MuiDataGrid: {
    styleOverrides: {
        columnHeader: {
          backgroundColor: "black",
        },
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.