-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to wrap text in cell of DataGrid #1040
Comments
Do you expect the height of the row to adapt to the number of wrapped lines? |
@oliviertassinari yes. |
Same here, I am considering going back to Table because of this. I google for quite some time and it seems the feature has not been released yet, but if there's any workaround please share :) |
Having dynamic row height is on the pipeline but it might take some time before it gets to production. |
Should we close as a duplicate of #417 and post the Popper workaround there? |
Can anybody help with an ES6 popper? |
Duplicate of #417 |
@dtassone not in tsx please but in js? |
This comment was marked as resolved.
This comment was marked as resolved.
@NavizDev Please try the following in your CSS: .MuiDataGrid-root .MuiDataGrid-cell {
color: tomato;
white-space: normal !important;
word-wrap: break-word !important;
} this should be working. |
here is a working solution using Tooltip: /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { Tooltip } from '@mui/material';
import { GridRenderCellParams } from '@mui/x-data-grid';
import { useEffect, useRef, useState } from 'react';
const RenderExpandableCell = (props: GridRenderCellParams) => {
const [isOverflowed, setIsOverflow] = useState(false);
const { value } = props;
const textElementRef = useRef<HTMLSpanElement | null>(null);
const checkOverflow = () => {
// Using getBoundingClientRect, instead of scrollWidth and clientWidth, to get width with fractional accuracy
const clientWidth = textElementRef.current!.getBoundingClientRect().width;
textElementRef.current!.style.overflow = 'visible';
const contentWidth = textElementRef.current!.getBoundingClientRect().width;
textElementRef.current!.style.overflow = 'hidden';
setIsOverflow(contentWidth > clientWidth);
};
useEffect(() => {
checkOverflow();
window.addEventListener('resize', checkOverflow);
return () => {
window.removeEventListener('resize', checkOverflow);
};
}, []);
return (
<Tooltip title={value} disableHoverListener={!isOverflowed}>
<span
ref={textElementRef}
style={{
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
}}
>
{value}
</span>
</Tooltip>
);
};
export default RenderExpandableCell; https://codesandbox.io/s/expandcelldemo-forked-6dzrqh?file=/src/App.tsx |
This works:
|
This is the best and most simple solution, thanks! |
Is there a way to do the same with datagrid headers? |
sx={{ '& .MuiDataGrid-columnHeaderTitleContainer': { whiteSpace: 'normal' }, }} |
My text in data grid cell was truncated, on mobile device. I added padding to make UI good along with this solution. getRowHeight={() => 'auto'} |
I'm trying to wrap text in a cell of the data grid. Is there a way to wrap text in a table column? I using
<DataGrid />
:The text was updated successfully, but these errors were encountered: