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

Tips for optimizing Jquery selectors to streamline recurring functions

I have 9 "service node" divs in my HTML code, each containing a hidden div and a button that triggers the rotation of the button by 45 degrees and reveals the hidden div. The challenge I am facing is that I have been using repetitive functions for each ser ...

Is there a method to introduce a line break for each piece of data that is shown?

I am currently working with an array and have successfully displayed it on the screen. My inquiry is whether it is feasible to insert a line break for each of the data points it presents. { name: "cartItems", label: "Product Name ...

Aligning Card in Center using Bootstrap

Having trouble centering the card properly, as a beginner I'm not sure what to do. </head> <body> <div class="container"> <div class="row justify-content-center"> <div class="col-md-4 co ...

Ways to fix a proxy issue within a React.js and Express application

My code is showing an error message: Error: Proxy error - Unable to proxy request /AppManager.jsx. Visit https://nodejs.org/api/errors.html#errors_common_system_errors for more details (ECONNREFUSED). react-dom.development.js:199 GET http://localhost ...

Analyzing the original data form versus the modified data

I'm dealing with a form in React that utilizes react-hook-form and the useFieldArray method for adding dynamic steps. The challenge I'm facing is how to compare the original data passed to the form with the edited data, in order to make correspon ...

What could be causing the malfunction of my token rotation feature in nextAuth?

I am developing a web application that involves working with an external API alongside my team member. We are making API requests using Next.js. I have implemented nextAuth for authentication, but I am facing issues with token rotation. After successful lo ...

The MUI DataGrid Pagination has been replaced due to an error: validateDOMNesting(...): <td> should not be nested within a <div>

I'm struggling with replacing the pagination in my DataGrid component from Material-UI. Every time I try, I encounter this console error: Warning: validateDOMNesting(...): <td> cannot appear as a child of <div> I've double-checked my ...

Creating a div that automatically scrolls along with the page as it reaches the edges of the viewport

My website features a floating box on the side of the page (Parent div) housing a child div with a position:sticky property that scrolls along with the page as it reaches the top of the viewport. See it in action here: https://codepen.io/Xanthippus480/pen/ ...

Tips on how to deactivate the Material UI DataGrid's next page button during API loading

This snippet pertains to the Material UI Datagrid component. In order to prevent users from moving to the next page while the API is still loading, I need to disable the Go to next page button. <DataGrid autoHeight getRowHeight={getRow ...

Executing a prop function within the useEffect hook: a step-by-step guide

I am attempting to address this warning in a react component Line 19:8: React Hook useEffect has a missing dependency: 'handleChange'. Either include it or remove the dependency array react-hooks/exhaustive-deps This is the component: ...

"React with Typescript - a powerful combination for

I'm facing an issue trying to create a simple list of items in my code. Adding the items manually works, but when I try to map through them it doesn't work. Apologies for any language mistakes. import './App.css' const App = () => { ...

Assigning alphanumeric characters to the axis for identification purposes

review the code in index.html <!DOCTYPE html> <html> <head> <title>D3 test</title> <style> .grid .tick { stroke: lightgrey; opacity: 0.7; } .grid path { stroke-width: 0; } .ch ...

Unexpected issue with sliding menu toggle implementation

I have been struggling to make a menu slide to the left when a button is clicked, and then slide back to its original position when the same button is clicked again. Although I have been using the toggle method, it doesn't seem to be working for me. I ...

HTML elements are positioned in alignment

I'm currently working on a website and I need some assistance in aligning my images properly. Here's what I have tried: However, I haven't been able to achieve the desired result with the following code: <img height="632" width="428" sr ...

Taking out the modal element from the document object model, causing the animation

I am currently working on a project using Next.js, Typescript, and Tailwind CSS. Within this project, I have implemented a modal component with some animations. However, I encountered an issue where the modal does not get removed from the DOM when closed, ...

Props and theme merge to create uniquely designed styled components with a thematic twist

Out of sheer curiosity, I've been incorporating styled-components into my React application. Within this framework, I make use of the recommended theme to ensure consistency in colors and sizes throughout. Currently, my approach looks something like ...

Ways to implement a delay in a function?

I'm looking for a way to introduce a delay in my function. Should I enclose the function within a delay function, or is there a different method to ensure that the animation doesn't trigger until 5 seconds after the page has loaded? var textTo ...

Is it possible to add a class to a child element deep within the component hierarchy while using TransitionGroup/CSSTransition in React?

I currently have a setup like this: Parent Component: <TransitionGroup> { items.map((child, index) => { // do something return ( <CSSTransition key={index} nodeRef={items.nodeRef} timeout={1000} classNames={'item ...

The Reactjs Side Panel

I'm having trouble getting my sidebar data to show up on the screen. I have the data set up in the sidebar.js file and I'm mapping it, but it's not displaying on the browser. What could be the issue? import React from "react"; impo ...

Crafting visually stunning interfaces with Material UI

I'm a beginner in Material Design and I could use some assistance with the following structure. Can anyone guide me on how to create this? https://i.stack.imgur.com/NpiVz.png I've managed to add a text box, but now I'd like to place a label ...