Styling the React Material UI DataGrid with the MuiDataGrid-window class using createMuiTheme or makeStyles / styled-components

I've been putting in a lot of effort to customize the css for the .MuiDataGrid-window in MaterialUi's DataGrid. I've been referencing css rules from https://material-ui.com/api/data-grid/

I managed to get it working within createMuiTheme for the root, but couldn't figure out how to style the window. I tried various combinations like MuiDataGrid-window or just 'MuiDataGrid-window' directly under overrides, but nothing seemed to work.

export const theme = createMuiTheme({
  overrides: {
    MuiDataGrid: {
      root: {
        backgroundColor: 'red',
      },
      window: {
        width: '120%',
      },
    },
  }
});

My next attempt was using a styled DataGrid component, but that also didn't yield any results. Both methods were unsuccessful. Using a styled component would be my preferred approach!

const StyledDataGrid = styled(DataGrid)({
  MuiDataGrid: {
    root: {
      backgroundColor: 'green',
    },
    window: {
      width: '120%',
    }
  }
});

Perhaps I'm completely off track.. But how can I style the CSS attributes in MUI's API such as .MuiDataGrid-mainGridContainer, .MuiDataGrid-overlay, .MuiDataGrid-columnsContainer, .MuiDataGrid-colCellWrapper, and so on?

Thank you very much and hopefully this information proves useful to someone else :)

Answer №1

When examining the applied styles, it is apparent that the window class element in a grid has two associated selectors (multiple classes):

.MuiDataGrid-root .MuiDataGrid-window

In order to apply these styles to child elements, such as the window within the grid root, both selectors must be targeted:

MuiDataGrid: {
  root: {
    backgroundColor: 'red',
    '& .MuiDataGrid-window': {
      backgroundColor: 'green'
    }
  }
}

The documentation for the grid component only lists one rule name: root

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Bootstrap navigation bar is experiencing issues and is not functioning properly, as the classes are not

<nav class="navbar navbar-default"> <div class="container-fluid"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" d ...

Ways to position a single item in the middle of a multi-column layout

I need help with aligning dynamic images in a 2-column layout. What's the best way to center a single image or collapse the columns when there's only one image? Currently, the single image is always placed in the left column. Is there a CSS-only ...

aligning content that has exceeded the boundaries

I have a list of dynamically created <a> tags without text, to which I apply background images. These icons are displayed within a <div> container using the float: left; style. As the row of icons becomes too long, it overflows and starts a ne ...

Updates made in MobX store are not displaying in the web browser

Why are the data changes not reflecting in the view after the api call? Here is the code snippet that might help: store.js import axios from 'axios'; import {encrypt, decrypt} from '../utils/pgp.js' import {observable, action, compute ...

Ways to prevent a MaterialUI Expansion Panel from automatically expanding

I am currently seeking a solution to automatically set the Expansion panel to expanded=false when the panel is disabled. Picture an expanded Expansion panel. Then, an event triggers and the Expansion Panel becomes disabled. The issue lies in the fact that ...

In Firefox, the functionality of applying background-position-y to a label when it is immediately preceded by a checked input[type=radio]

CSS selector input[type=checkbox]:checked + label is not functioning properly in Firefox browser! label { display: block; font-family: 'Muli'; font-size: 14px; color: #666; vertical-align: top; background: url("https://s31.postimg. ...

Optimal data structure for storage in a Next.js project with TypeScript

What is the appropriate data type for store in export let store: any; other than any? I have used @ts-igore to suppress TypeScript errors on the last line. How can I address the TypeScript error for that as well? I mentioned the boilerplates utilized in ...

The jQuery menu is malfunctioning in Internet Explorer due to the Document Mode being set to Quirks

I am encountering an issue where the below code is not functioning properly in Internet Explorer's document mode quirks. Each time I hover over the submenu, its length doubles unexpectedly. Can someone please provide assistance with this matter? < ...

Enhancing react-to-print functionality for optimal performance across various browsers and mobile platforms

Currently, I am developing a sample react-to-print resume template to be included in a larger portfolio website. While testing the page on Chrome and Edge browsers on a laptop, everything seems optimized. However, there are issues when using Firefox; the b ...

Switch the background color when a radio button is chosen

For my quiz on test practice with an array of questions, each question includes five radio buttons, but only one is correct. Initially, all five options have a gray background. Upon selecting a wrong option, it changes to red. If another incorrect option i ...

I recently designed a form using a combination of HTML and JavaScript in order to display different dialogues depending on the number of selections made. Unfortunately, the alert function does not seem to be functioning

The concept is to have users select options and then receive employment sector suggestions based on their selections. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

Is it possible to implement dependency injection within a .css document?

I have a C# .NET 6 application. Some of the web pages (Razor Pages) in the app use dependency injection to inject configuration into the Razor Pages (.cshtml files), allowing certain config elements to be displayed in the user interface. My query is, can ...

Are you a fan of Mui Buttons and want to keep your Font Family consistent?

When it comes to typography, I like to set a specific theme but I prefer to keep the font family of Mui buttons unchanged. typography: { fontFamily: ["Baloo Bhaijaan 2", "cursive"].join(", "), button: { fontFamily: "Ba ...

Using React.js, the useState() function can effectively manage state changes by

Currently, I am delving into learning react.js with hooks and have come across a challenge involving an array of objects. Shown below is the code snippet: const [stories, setStoreis] = useState( [ { name: "1st Story", sid: "1", appart ...

Struggling with retrieving empty parameters, queries, and body from an Axios API call for the past three days. It's a learning experience as I am new to the MERN stack

There seems to be an issue where only empty JSON like {} is coming as output. I am looking for a way to access the parameters sent from the routes in this scenario. On the Frontend: let api = axios.create({ baseURL: "http://localhost:5000/validateSignI ...

Ways to designate a tab as active

Having trouble styling the active tab in my tabbed menu created with Bootstrap. The active class seems to only affect the first tab. How can I make it work for all tabs? Check out this screenshot for reference. Below is the code snippet: <script ...

The case of the elusive Firefox overflow: hidden glitch

Recently, I integrated an image slider into my web design and it displayed perfectly on Internet Explorer and Chrome. However, when viewed on Firefox, I encountered a strange problem where the images in the slider were being pushed towards the right side o ...

Instructions on how to navigate to a class page by clicking a button in a ReactJS interface

I am currently working with React and have implemented 3 classes in separate files. The App.js file contains a navbar and button, which when clicked, displays a table from 'Table.js'. I have also added buttons in front of each row in the table th ...

Switch up the tab content with the help of a router

I need to modify the "tab content area" in a react application by clicking on a button using react-router. There are two tabs, and I want to update the content of one tab when the button is clicked. The rest of the page should remain unchanged except for ...

Utilizing Material UI for autocomplete forms with dynamic label inputs

Is it possible to display both the title and year in the label of an autocomplete form? I encountered an issue with the standard Material UI demo when attempting to use an array to show both title and year in the form label. The error pertained to lowerca ...