-
-
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
[data grid] Easily allow header text to wrap #898
Comments
@iccube-real @oliviertassinari this looks like a duplicate of #417 as both are related to multiplies support in cells and since table headers are just a special type of cell it would be appropriate to have that functionality for both when we pick it up. |
@DanailH , it's the same 'family' yes. You want to fix the maximum number of lines you want manually (height in px is not the point). Imagine a column that calculates a ranking (it's a small number) but with a bigger title (e.g. 'Developers month ranking'). You don't want your column take too much width but still want to see the whole text of the header -> two lines might look better. After you want ellipsis... Ideally, it's a competition between the width and the title height to better fit the table that depends on perception (so some users might like more agressive algos than others). Looks for know as a stick in the moon.. Two questions :
_hope it helps. PS : I'll try to add some images so it's clear |
I'm not sure that we should treat this issue as a duplicate of #417. The problem surfaced by @iccube-real seems related be can be solved independently. There is a tension between the width of the columns and the height of the header. It sounds like he should expose the tool required for him to implement his tradeoff.
We don't support it easily right now. I think that it requires simplifying the CSS of the header first, e.g. duplicated
The width can be defined for each column definitions. So you can force a specific value. Otherwise, you can listen to update with this private API: <DataGrid
onStateChange={({ state }) => {
console.log("state", state.columns.lookup.id.width);
}} I have renamed the issue to focus on the text wrapping problem. We can only focus on one problem at a time and it seems to be the most relevant one. |
The same issue applies on rows as well. I was able to jerry rig it but it was not pretty. This may be a bigger discussion about being able to more easily override certain styles. |
One way to do it is to apply a css class on the header and override the const useStyle = makeStyles({
root: {
"& .wrapHeader .MuiDataGrid-colCellTitle": {
overflow: "hidden",
lineHeight: "20px",
whiteSpace: "normal"
}
}
}); Check out the full demo https://codesandbox.io/s/header-wrap-text-xzscx?file=/demo.tsx You can also increase the size of the header row using the |
@dtassone I think that we should remove the need for using |
How can I just hide the headerName if it is too big to avoid the displaying "Us..." for "User Name"? It looks ugly in the table. |
In ref to this #898 (comment)
This was how I was able to do it
|
I was able to find that in <DataGrid columns={cols} rows={...} autoHeight={true} headerHeight={80} disableColumnMenu={true} sx={{
'& .MuiDataGrid-columnHeaderTitle': {
textOverflow: "clip",
whiteSpace: "break-spaces",
lineHeight: 1
}
}}> |
Would be great to have auto-height header adjustment if text overflows actual width. I would appreciate it in v6 #3287 |
@iggyzap I tried setting headerHeight to be higher but that doesn't fix it. |
This came up in StackOverflow: https://stackoverflow.com/questions/75943264/how-to-word-wrap-the-column-from-material-ui-datagrid/75944212#75944212. Here's the styling I put in my solution there:
This is similar to what @iggyzap has but also dealing with allowing the height to handle more than 3 rows of text (though after trying this out in my own project, I'm finding issues with the |
Yep! It was helping me. Thanks again, @ryancogswell ! We need some kind of feature to do this easily |
Thanks @iggyzap! However, if I remove the To counteract this, I added <DataGrid
columns={columns}
rows={rows}
autoHeight
sx={{
'& .MuiDataGrid-columnHeaderTitle': {
whiteSpace: 'break-spaces',
lineHeight: 1,
},
'&.MuiDataGrid-root .MuiDataGrid-columnHeader--alignRight .MuiDataGrid-columnHeaderTitleContainer': {
pl: 1,
},
}}
/>; |
Baking this feature in would be really helpful. It's really hard to get this right in a way that doesn't screw something else up: Screen.Recording.2023-12-22.at.08.54.38.movFor reference, note that AG Grid seems to do this wrapped header thing well. |
We tried implementing this, but we had difficulties getting the header height to adapt to the number of rows of text as the contents wrapped. It would be good to have a native option for this. |
The irony of the DataGrid is that for how much it's supposed to do for you with the display of the table, I end up needing to hack its styles constantly to get a reasonably intuitive interface for anything more than a handful of simple columns with short cell values and header names. |
Just want to add my voice to this feature request. I think it would be very interesting for accessibility to have labels in the header that wraps according to the available width, so that we can always see them whatever the text zoom, page zoom and so. I'm able to make it work by tweaking CSS, but it would be much better if the component handle it directly. |
Summary 💡
Sometimes header titles are too big to fit in one line and we would like to have them in multiple lines.
Ideally, we could have a kind of outfit that is based more on the columns cells width, like Excel, but this one is not trivial. And as the answer might depend on some end users input we do not know in advance either how many rows or size we will get.
Examples 🌈
A very simple example : https://codesandbox.io/s/material-demo-forked-g6ibb
Motivation 🔦
The text was updated successfully, but these errors were encountered: