Skip to content
+

Data Grid - Layout

The Data Grid offers multiple layout modes.

Flex parent container

The Data Grid can be placed inside a flex container with flex-direction: column. Without setting the minimum and maximum height, the Data Grid takes as much space as it needs to display all rows.

Press Enter to start editing

Minimum and maximum height

In the demo below, the Data Grid is placed inside a flex container with a minimum height of 200px and a maximum height of 400px and adapts its height when the number of rows changes.

Percentage dimensions

When using percentages (%) for height or width, make sure that the Data Grid's parent container has intrinsic dimensions. Browsers adjust the element based on a percentage of its parent's size. If the parent has no size, the percentage will be zero.

Predefined dimensions

You can predefine dimensions for the parent of the Data Grid.

Press Enter to start editing

Height prop

Use the height prop to set a fixed height directly on the Data Grid, without a parent element with an explicit height. It accepts a number (in pixels), a CSS length such as '50vh', a percentage, or a calculation such as 'calc(100vh - 200px)'. Percentage values require a parent element with an explicit height. For content-based sizing, use a flex parent container instead of values such as 'auto', 'min-content', 'max-content', or 'fit-content', which this prop does not support. To change the height, update the prop instead of sx or style, because the prop also sets the minimum and maximum height.

Press Enter to start editing

Overlay height

When data grid has no content, overlays (such as "Loading" or "No rows") take the height of two rows by default.

To customize the overlay height, use the --DataGrid-overlayHeight CSS variable.

Press Enter to start editing

Auto height

The autoHeight prop enables the Data Grid to adjust its size based on its content. This means that the Data Grid's height will be determined by the number of rows, ensuring that all rows will be visible to the user simultaneously.

Press Enter to start editing