MUI X Data Grid squeezes its columns or does not scroll sideways
The grid renders with zero height or widthShort 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.
Fix it fast
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/2Match what you see, then jump to its fix
- 1
The grid is invisible or has zero height.The parent container has no sizeFix - 2
Columns shrink to fit and there is never a scrollbar.Every column uses flex, so they always fitFix - 3
A column ignores its width.width is set on a column that also has flexFix - 4
The grid height does not follow the content.autoHeight used together with a height propFix
- 1
What does the error look like?
The grid renders with zero height or widthAll 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 devConfirmed by mui.com
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 devConfirmed by mui.com
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 width2Fix
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 devConfirmed by mui.com
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 devConfirmed by mui.com
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
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 fixWeb apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fix