-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[DataGrid] Dynamic row height #417
Comments
@ronnyroeller thanks for the feature request. It's definitely something we were expecting. We are happy to see it surface :). For the virtualization to work, the grid needs to know the size of all the rows. Benchmark |
Thanks a lot for the quick reply, @oliviertassinari Very helpful! Virtualization is indeed a good point. I was wondering if setting the maximal row height could help with this. For example, if one knows that a row can be max twice the "normal height" -> it might still be possible to do the required calculations (although with a bit more slack). Background: |
@ronnyroeller We will definitely implement variable and dynamic row heights. There are two standard use cases (probably not even advanced). A We have no plans to implement a data grid without virtualization. |
We managed to implement this with css and it works for us. No need to set row height on the react datagrid element after this:
Issue was positioning and max-height. After this, everything is dynamic for row height |
I have used react-virtuoso for virtualization with dynamic row heights. It supports dynamic row heights out-of-the-box. It is a less-popular package than react-virtualized or react-window, which as far as I know don't support dynamic heights. It does the job pretty well. |
cc @petyosi 🙃 |
@balihoo-wwilkins Thanks a lot for sharing your workaround! I tried it out but it seems to confuse the scrolling. If there are items that are higher than |
@oliviertassinari You could use the approach Apple does with UIKit, and provide an estimated row height. Then you can continuously update the estimated full height of the table to a more correct value as the user scrolls to reveal more rows (which then report their actual heights). That way you don't need to know the size of all rows up front. |
A possible workaround, a popup shown on hover: https://codesandbox.io/s/expandcelldemo-forked-2owvu?file=/src/renderCellExpand.tsx I have tried to improve the first version built by @dtassone |
the only workaround found is that: |
i found the workaround with CSS as
And virtualization works as well as usual. |
Thanks @oliviertassinari - I forked your approach for another UX - https://codesandbox.io/s/expandcelldemo-forked-rs0hx?file=/src/renderCellExpand.tsx - maybe it's helping someone ( https://rs0hx.csb.app/# ) |
I feel like this should be part of the API for the DataGrid |
Is there a way to edit that component the same way you edit a normal string cell? Currently you can't edit the cell once it reaches the popup state. |
The CSS fix doesn't seem to work on Safari (iPhone or Mac). The rows end up broken, with different cells somehow getting different height. Works well for Chrome and Firefox... max-heght: none seems to work on Chrome, Firefox and Safari.
|
Just wanted to mention that this CSS from above *mostly works for me. But doesn't work with Column Pinning. The cells in the Pinned Column take on their own height which breaks the whole grid
|
@blazinaj Did you find any workaround for pinned columns? |
Hey all, we're working in adding support for row height based on the content in #4859. We would love to have feedback from the community on how to make this feature perfect. Documentation: https://deploy-preview-4859--material-ui-x.netlify.app/x/react-data-grid/rows/#dynamic-row-height |
I am getting this error My code :
Default code: https://deploy-preview-4859--material-ui-x.netlify.app/x/react-data-grid/rows/#dynamic-row-height |
@d-s-i are you able to reproduce it in a codesandbox with your TS config ? The following should work, but I would have expected TS to work without the explicit casting getRowHeight={() => 'auto' as const} |
I'm trying to use the new dynamic row height functionality in Material UI. When I add the line "getRowHeight={() => 'auto'}" as mentioned here, I get the warning in the console and grid is not displayed properly. There are missing rows and dynamic row height does not work. I understand that I'm passing a string where there should be a number but I can't find where or how. If I comment the line "getRowHeight={() => 'auto'}", no warnings and works normally but no dynamic row height of course. My code and warnings are below. Failed prop type: Invalid prop My code is:
My test data is very basic like this https://i.stack.imgur.com/R6HC3.jpg |
@AhenkEU The dynamic row height was not released in the NPM package yet. To experiment with it, you need to use the preview package available by clicking the "Open in CodeSandbox" button in any demo in https://deploy-preview-4859--material-ui-x.netlify.app/x/react-data-grid/rows/#dynamic-row-height |
Oh, I thought it is live and useable already. Thank you :) |
@krishnagupta21 By default, no. The dynamic row height always uses the row content so it will reduce the height to the height of the |
Will this support a tree view with pinned columns? Scrolling on expanded grouped rows is a bit janky. The mouse is not always positioned over the scroll bar and it studders a bit when dragging the scroll bar up. Here is another example using the premium grid and grouping. Try expanding a few nodes and scroll down and up. |
Indeed there is something wrong with the scrolling there, it stops scrolling from time to time ... |
@masull The dynamic row height uses a lazy approach, so it only knows the true height after rendering the row. To calculate the size of the scrollbar, before a row is rendered, we use an estimation. The inconsistency might be explained because the true height is too different from the estimation. You can try to tweak the |
Okay, thanks, I'll give it a try. |
I have tried various methods, the new, getRowHeight={() => 'auto'} works with pinned columns, but there is a performance penalty when vertically scrolling on say, 30+ treeData rows. The css posted above is promising (performance is fine) except it does not work for pinned columns. |
You can now easily set the row height to dynamically fit the content by adding:
as a prop to the DataGrid component Heres a link to the documentation explaining this - https://mui.com/x/react-data-grid/rows/#dynamic-row-height |
If I am using DataGrid pagination together with autoheight feature is there a way I can prefetch the next page and set the correct height and avoid calling estimatedRowHeight. Right now I can go back to the previous page and there is no flickering since the size is already calculated, I was wondering if the similar case is possible by prefetching the next page with swr for example. |
So, for me it worked by using both `getRowHeight` and `rowHeight`, where `getRowHeight `can only be a **string** and `rowHeight `can only be a **number**
When Read This Document to get have more insight on this issue.
|
Summary 💡
I want to show text in one of the cells. Text can have different length and might span multiple lines. Today, data-grid seem to allow only a fixed
rowHeight
. I'd like to set this to dynamic - so the row is as high as the content requires. Alternatively, for my use case also something likemaxRowHeight
would work: I would define the maximal height of a row and the grid uses up to themaxRowHeight
- but less if there is less content.Examples 🌈
Motivation 🔦
I want to show in one of the columns text that the user entered (or a snippet of it).
The text was updated successfully, but these errors were encountered: