Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

MUI X Data Grid squeezes its columns or does not scroll sideways

ErrorThe grid renders with zero height or width

Short answer

A MUI X Data Grid scrolls sideways only when its columns are wider than the grid itself. The usual blockers are a parent with no size, flex columns that always fit the container, and flex set together with width. Give the parent real dimensions and use width or minWidth on the columns.

  • Applies to MUI X Data Grid 8, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the grid's parent in browser DevTools. If its computed width or height is 0, start with the first cause.

    grep -rn "<DataGrid" src/
  2. 2Match what you see, then jump to its fix

    1. 1The grid is invisible or has zero height.The parent container has no sizeFix
    2. 2Columns shrink to fit and there is never a scrollbar.Every column uses flex, so they always fitFix
    3. 3A column ignores its width.width is set on a column that also has flexFix
    4. 4The grid height does not follow the content.autoHeight used together with a height propFix

What does the error look like?

  • The grid renders with zero height or width
  • All columns are squeezed into the container and no horizontal scrollbar appears

Cause 1 of 4

The parent container has no size

1Check

The grid has no size of its own; it fills its parent. A percentage size on a parent with no size resolves to zero.

grep -rn -B2 "<DataGrid" src/

2Fix

Give the container an explicit height and a width.

<div style={{ height: 400, width: '100%' }}>
  <DataGrid rows={rows} columns={columns} />
</div>

3Verify

The grid now shows its rows.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 2 of 4

Every column uses flex, so they always fit

1Check

flex divides the remaining space among columns, so flex columns fill the grid. Scrolling only starts when fixed-width columns together exceed the grid width.

grep -rn "flex:" src/

2Fix

Give columns a width, or add minWidth so they stop shrinking.

const columns = [
  { field: 'name', headerName: 'Name', width: 220 },
  { field: 'email', headerName: 'Email', width: 260 },
  { field: 'role', headerName: 'Role', width: 200 },
];

3Verify

Make the window narrower than the combined widths. A scrollbar appears.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 3 of 4

width is set on a column that also has flex

1Check

flex does not work together with width; when both are set, flex overrides width.

grep -rn "flex" src/ | grep width

2Fix

Keep one of the two. To bound a flex column, use minWidth and maxWidth.

{ field: 'name', flex: 1, minWidth: 150, maxWidth: 400 }

3Verify

The column keeps its range as the window resizes.

npm run dev

Confirmed by mui.com

Did this fix it?

Cause 4 of 4

autoHeight used together with a height prop

1Check

The height prop cannot be used together with autoHeight.

grep -rn "autoHeight" src/

2Fix

Use autoHeight alone, or a sized container alone.

<DataGrid autoHeight rows={rows} columns={columns} />

3Verify

The grid grows with its rows.

npm run dev

Confirmed by mui.com

Did this fix it?

How do I stop it coming back?

  • Set width on columns that must never shrink, and flex only on one or two filler columns.
  • Test the grid at a narrow window width.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

MUI X Data Grid shows the wrong page size or resets to page one

The grid jumps back to page 1 while server data loads

Data Grid pagination breaks for four documented reasons: Pro and Premium need the pagination prop, the free grid caps pages at 100 rows, server mode needs paginationMode and a stable rowCount, and and autoPageSize cannot be combined with autoHeight.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.