Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable hover effect on MUI DataGrid

I'm struggling on small detail that would be to disable the hover effect of a MUI Datagrid row.

I can't find an easy way to do it, and reading the API documentation didn't help me.

How would you do it ?

<DataGrid
            columns={COLUMNS}
            rows={dailyReportItems}
            pageSize={pageSize}
            autoHeight
            onPageSizeChange={(newPageSize) => setPageSize(newPageSize)}
            pageSizeOptions={[10]}
            rowsPerPageOptions={[10]}
            disableSelectionOnClick
            getRowId={(row) => row.date}
            components={{
                NoRowsOverlay: () => (
                    <Stack
                        height="100%"
                        alignItems="center"
                        justifyContent="center"
                    >
                        Aucun résultat
                    </Stack>
                ),
                NoResultsOverlay: () => (
                    <Stack
                        height="100%"
                        alignItems="center"
                        justifyContent="center"
                    >
                        Aucun résultat sur ces filtres
                    </Stack>
                ),
            }}
            sx={{
                ".MuiTablePagination-displayedRows, .MuiTablePagination-selectLabel":
                    {
                        marginTop: "1em",
                        marginBottom: "1em",
                    },
            }}
        />
like image 429
Enzo Avatar asked Oct 24 '25 06:10

Enzo


1 Answers

It seems only targeting .MuiDataGrid-row:hover is part of the way but will leave you with an annoying glitch as seen below.

glitch

This is because it seems to be adding a 'Mui-hovered' class temporarily which causes said glitch.

Making both transparent fixed it for me with no hover and no glitch.

// Neutralize the hover colour (causing a flash)
"& .MuiDataGrid-row.Mui-hovered": {
backgroundColor: "transparent",
},
// Take out the hover colour
"& .MuiDataGrid-row:hover": {
backgroundColor: "transparent",
},
like image 151
Jason Dainter Avatar answered Oct 26 '25 20:10

Jason Dainter