Issue with vertical cell alignment in MUI x-data-grid persists following the latest update to version 7.2.0

After updating my MUI app to the latest npm packages version, specifically upgrading x-data-grid from 5.17.9 to 7.2.0, I encountered an issue.

In my application, I utilize a grid where certain columns are populated using the renderCell property:

const cell = (props: GridRenderCellParams<any, string>): JSX.Element => (
  <Typography sx={isGood} key={props.value}>
    {props.value}
  </Typography>
);

const columns: GridColDef[] = [
  {
    field: 'text',
    headerName: 'TEXT',
    renderCell: cell,
    // ...
  },
];

Previously, everything was functioning correctly with the cells being vertically and horizontally centered like this:

https://i.sstatic.net/xnLQl.png

However, after the update, the vertical alignment of the cells is off as they now appear at the top:

https://i.sstatic.net/0ifZ1.png

I am seeking assistance in understanding what has changed causing this misalignment and how I can revert back to the original appearance. Below is a snippet illustrating the structure of my code:


export const isGood = {
  color: 'green',
  fontWeight: 'bold',
};

const cell = (props: GridRenderCellParams<any, string>): JSX.Element => (
  <Typography sx={isGood} key={props.value}>
    {props.value}
  </Typography>
);

const columns: GridColDef[] = [
  {
    field: 'text',
    headerName: 'TEXT',
    align: 'center',
    headerAlign: 'center',
    width: 150,
    renderCell: cell,
    editable: false,
    flex: 1,
    disableColumnMenu: true,
    sortable: false,
  },
];

const rows = [
  {
    id: 1,
    text: 'T1',
  },
  {
    id: 2,
    text: 'T2',
  },
  {
    id: 3,
    text: 'T3',
  },
];

export default function RenderCellGrid() {
  return (
    <div style={{ height: 300, width: '100%' }}>
      <DataGrid
        hideFooter
        disableRowSelectionOnClick
        disableColumnSelector
        autoHeight
        columnHeaderHeight={40}
        rows={rows}
        columns={columns}
        rowHeight={85}
      />
    </div>
  );
}

Answer №1

After some investigation, I discovered the answer in the migration guide:

https://mui.com/x/migration/migration-data-grid-v6/#css-classes-and-styling

According to the guide:

The default display property of the cell element is not set to flex. You can add display: 'flex' to the column definition to regain that functionality.

By adding 'flex' to my column, I was able to restore the original appearance automatically.

Answer №2

Swap out your cellphone with

const cell = (props: GridRenderCellParams<any, string>): JSX.Element => (
    <Box sx={{height:85,display:"flex", flexDirection:"row", alignItems:"center", justifyContent:"center"}}>
        <Typography sx={isGood} key={props.value}>
            {props.value}
        </Typography>
    </Box>
);

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 attribute 'title' cannot be found within the type 'IntrinsicAttributes & IProps'

Hello, I am currently facing an issue where I am trying to hide an item in a different view using interfaces. The specific error I am encountering is mentioned in the title of this query. Let me provide you with part of the code to give you more context: ...

The method toLowerCase is not found on this data type in TypeScript

I am currently working on creating a filter for autocomplete material. Here is an example of my model: export class Country { country_id: number; name: string; } When calling the web method ws: this.ws.AllCountry().subscribe( ...

The key is not applicable for indexing the type as expected

Here is the TS code I am working with: type Fruit = { kind: "apple" } | { kind: "grape"; color: "green" | "black" }; type FruitTaste<TFruit extends Fruit> = TFruit["kind"] extends "apple" ? "good" : TFruit["color"] extends "green" ? "good" : ...

having trouble accessing the req object during the post fetch operation

Snippet of the node.js script: const express = require('express'); const path = require('path'); const bodyParser = require('body-parser') const app = express(); const cors = require('cors'); app.use(express.static( ...

Switch up the navigation section's background based on the specific page route in Next.js

As I develop my NextJs application, I have set up a homepage as well as routes to products and about pages. My goal is to display a unique header image in the Nav section of each component, sourced from an API when a user switches between pages. How can ...

Visualization of extensive datasets in JavaScript

I'm currently developing a dashboard in JS for displaying sales data plots to users. Can anyone recommend a JavaScript library that meets the following criteria: Capable of plotting a large number of points (ex: 100k or more) Interactive functional ...

How can I incorporate Bootstrap/Semantic UI into an Express project without relying on external CDNs

After downloading the minified version of Bootstrap and placing it in the root directory of my project, I added the following code to a HTML file located in /views/: <link rel="stylesheet" href="/bootstrap.min.css"> Despite this, the page remained ...

Altering the character by striking a key

I have a canvas with custom styling. In the center of the canvas is a single letter. Please see the code below for reference. The goal is to change the displayed letter by pressing a key on the keyboard. For instance: Letter A is centered in the canvas: P ...

When a div is floated to the left and another div is floated to the right, the

I would like the footer to display an image aligned to the left and some additional text (an inline ul with links) aligned to the right within the footer. Here is the CSS & HTML: footer { clear: both; background: #113551; width: 90%; ma ...

npm encountered an issue when attempting to install a package from a local directory: EISDIR: illegal operation on a directory, read

While attempting to add my compiled TypeScript output as a local package using npm, this error appears: $ npm install --save ../app/out npm ERR! eisdir EISDIR: illegal operation on a directory, read npm ERR! eisdir This is most likely not a problem wit ...

Exploring the intricacies of a specific Angular route through dialogue

Currently, I am working on enhancing the user experience by allowing data editing through dialogs. I have opted to move this functionality to a separate component so that it can read and edit the designated data efficiently without cluttering the main page ...

Encountering difficulties while trying to configure Node.js in VS Code

Recently, I attempted to set up a ReactJS application on my Windows system using the command below: npx create-react-app my-app However, I encountered an error message during the process: PS C:\Users\santu\React-JS> npx create-react-app ...

Testing with Selenium to confirm the presence of a specific CSS attribute within the style attribute

I am looking to create a Selenium IDE test that will confirm the value of the bottom attribute in the "style" section below. How can I go about writing a test for this considering: The Xpath to the element is: xpath=/html/body/div/div[3]/div[2]/div/div/di ...

Migrating from Styled Components to Material-UI: Is it possible for Material-UI to apply `withStyles()` to a div element

My app's logic and operation aspects are solid, so I can't risk altering components that switch from <FriendlyComponentName /> to <div css={{styleObject}} /> using Material makeStyles() or similar methods. An example of existing Styl ...

Troubleshooting CSS navigation bar hamburger dilemma

Currently, I am facing an issue with a toggle button on my website. When I click on the hamburger menu, the navigation bar does not show up even though the toggle feature is working perfectly fine. I have tried combining different sources to solve this pro ...

The error message "The element 'router-outlet' is unrecognized during the execution of ng build --prod" appears

I encountered a specific error message when running ng build --prod, although the regular ng build command works without issue. Error: src/app/app.component.html:1:1 - error NG8001: 'router-outlet' is not recognized as an element: 1. If 'rou ...

Can someone tell me where I can locate the CSS file once I've finished using Scene Builder?

Currently, I am working on my database project using Scene Builder. I have applied some CSS styling and would like to locate the CSS file in order to attach it to my IntelliJ project for further code editing. Can anyone guide me on where to find the CSS ...

ReactJS: Improving state management with ShouldComponentUpdate

Is it possible to utilize shouldComponentUpdate for managing states? I could verify by checking: shouldComponentUpdate(nextProps, nextState) { return this.state.value != nextState.value; } However, this approach may not be practical when dealing with ...

It is not possible to highlight the text that appears in the title of the tooltip in React MUI

Within my react application, there is a component that utilizes the code snippet below: <FormControlLabel labelPlacement="top" control={ comp?.manualInput ? ( <TextField name="price" type= ...

Utilizing space with margin and padding in Bootstrap 5

I recently started experimenting with bootstrap 5, but I'm feeling quite disoriented. The layout I have created includes some blue elements (borrowed the sidebar from this source) and now I am attempting to replicate this design. https://i.sstatic.ne ...