-
-
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGrid] Autoheight with maxHeight or limit for displayed rows #3524
Comments
Setting a The number of rows will exceed the available space: <div style={{ height: 300, overflow: "auto" }}>
<DataGrid autoHeight={false} />
</div> The number of rows will not exceed the available space: <div style={{ height: 'auto', overflow: "auto" }}>
<DataGrid autoHeight={true} />
</div> Does it solve your case? |
Thank you for your answer @m4theushw , but no, unfortunately it doesn't cover my case. Let me provide some examples which looks bad in my project (when |
What I would recommend is to not use the |
Try this: rows per page and on parent container and Datagrid prop |
Not so good if there are less than rpp rows in your dataset. Try this... |
Mine was like this |
=> afterstruggling for a while finally this works for me like a magic:
now I have complete control over the width and height through the top level box #DataGridContainer
|
I managed to get this working, though I had to use some pretty hacky css selectors in the SX. Height is controlled by the parent Box
|
am i the only one who finds these "styling" solutions abysmal? |
Hi! Is there a solution that works with tree data as well? In this case the number of visible rows can change, so it's not enough to simply count all rows. Is there a way to get the number of visible (parent / child) rows before they are rendered? It would be great if MUI DataGrid had a EDIT: Veeery early version of an experiment to make it work with tree data and fixed row height: const useAutoMaxHeight = ({
api,
rowHeight,
}: {
api: GridApiPro
rowHeight: number
}) => {
const [isAutoHeightEnabled, setIsAutoHeightEnabled] = React.useState(true)
useEffect(() => {
if (api.subscribeEvent && api.state && api.instanceId) {
return api.subscribeEvent('stateChange', () => {
const visibleRowIds = gridExpandedSortedRowIdsSelector(
api.state,
api.instanceId,
)
// Table height without header and pinned rows
const tableHeight = rowHeight * visibleRowIds.length
const viewportHeight = window.innerHeight
setIsAutoHeightEnabled(tableHeight < viewportHeight)
})
}
}, [api, rowHeight])
return isAutoHeightEnabled
}
export const MyDataGrid = (props) => {
const apiRef = useGridApiRef()
const isAutoHeightEnabled = useAutoMaxHeight({
api: apiRef.current,
rowHeight: props.rowHeight,
})
return (
<div
style={{
height: isAutoHeightEnabled ? 'auto' : '100vh',
overflow: 'auto',
}}
>
<DataGridPro
apiRef={apiRef}
autoHeight={isAutoHeightEnabled}
...
/>
</div>
)
} |
Other workaround can be: <DataGrid
autoHeight={true}
sx={{
'.MuiDataGrid-virtualScroller': {
overflowY: 'auto !important',
// example of maxHeight
maxHeight: 'calc(100vh - 100px) !important',
},
}}
...otherProps
/> |
Duplicates
Latest version
Summary 馃挕
For my current development i need to have a
DataGrid
embeded into the some Summary Page content (for ex.).So before and after
DataGrid
component i have some data.DataGrid
should be flexible (emptyDataGrid
looks not good enough in my case) and for 1 row should be small (like it already happens when autosize is switched on). But for more than 5 rows (for ex.) i need to prevent furtherDataGrid
stretching to keep rest content visible.See raw example below.
Examples 馃寛
Here is example https://codesandbox.io/s/autoheightgrid-material-demo-forked-r48po?file=/demo.tsx .
In that example i've met really close implementation to what i want, but unfortunately datagrid header and footer stay unpinned and dissapear on scrolling. But i need behaviour like
DataGrid
without autoheight with specified height.Is it possible to solve my problem somehow with current functionality?
Motivation 馃敠
I'm totally ok with:
DataGrid
's header/footer (throughMuiThemes
, if it will not brake anything inDataGrid
virtualization)Order ID 馃挸 (optional)
No response
The text was updated successfully, but these errors were encountered: