Skip to content

Data Grid - Row height

Customize the height of your rows.

Static row height

By default, the rows have a height of 52 pixels. This matches the normal height in the Material Design guidelines.

Use the rowHeight prop to change this default value, as shown below:

Desk
Commodity
Trader Name
Trader Email
Quantity
D-8876
Adzuki bean
Miguel Goodman
49,282
D-4537
Sugar No.11
Alejandro Hanson
48,154
D-9162
Corn
Lester Tucker
54,024
D-8736
Rapeseed
Phillip Gardner
11,286
D-9415
Wheat
Lois Blair
63,063
D-5600
Sugar No.14
Ellen Vaughn
17,731
D-7119
Soybean Oil
Nina Townsend
25,453
D-6263
Oats
Dora Barrett
92,863
D-6173
Soybeans
Lois Nunez
68,211
D-324
Sugar No.11
Elsie Olson
8,157
D-139
Soybeans
Lettie Reeves
76,676
D-6844
Cotton No.2
Patrick Sims
70,370
D-5335
Soybean Oil
Joe Ramos
93,744
D-9710
Soybeans
Carlos Rogers
62,746
D-5731
Wheat
Alma McCoy
59,242

Rows per page:

1–100 of 100

Press Enter to start editing

Variable row height

If you need some rows to have different row heights this can be achieved using the getRowHeight prop. This function is called for each visible row and if the return value is a number then that number will be set as that row's rowHeight. If the return value is null or undefined, then the rowHeight prop will take effect for the given row.

id
username
age
1
@akizugsaf
51
2
@we
58
3
@wiil
19
4
@vibopri
45
5
@haot
11

Rows per page:

1–5 of 5

Press Enter to start editing
const getRowHeight = React.useCallback(() => { ... }, []);

<DataGridPro getRowHeight={getRowHeight} />

Dynamic row height

Instead of a fixed row height, you can let the data grid calculate the height of each row based on its content. To do so, return "auto" on the function passed to the getRowHeight prop.

<DataGrid getRowHeight={() => 'auto'} />

The following demo shows this feature in action:

id
username
age
bio
0
@vi
69
Pellentesque ac metus velit.
1
@kuev
72
Pellentesque ac metus velit. Nullam cursus tincidunt auctor. Maecenas non felis venenatis, porta velit quis, consectetur elit. Nam ullamcorper ligula id consectetur auctor.
2
@zom
39
Nam ullamcorper ligula id consectetur auctor. Vestibulum commodo et odio a laoreet. Nulla venenatis justo non felis vulputate, eu mollis metus ornare.
3
@ja
26
Maecenas non felis venenatis, porta velit quis, consectetur elit. Nullam cursus tincidunt auctor. Nam ullamcorper ligula id consectetur auctor.
4
@duf
74
Phasellus et ultrices dui. Pellentesque ac metus velit. Vestibulum commodo et odio a laoreet.
5
@sacuj
48
Vestibulum in massa nibh. Vestibulum in massa nibh. Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Fusce facilisis egestas massa, et eleifend magna imperdiet et.
6
@tiftogo
66
Pellentesque ac metus velit. Fusce facilisis egestas massa, et eleifend magna imperdiet et.

Rows per page:

1–100 of 200

The dynamic row height implementation is based on a lazy approach, which means that the rows are measured as they are rendered. Because of this, you may see the size of the scrollbar thumb changing during scroll. This side effect happens because a row height estimation is used while a row is not rendered, then this value is replaced once the true measurement is obtained. You can configure the estimated value used by passing a function to the getEstimatedRowHeight prop. If not provided, the default row height of 52px is used as estimation. It's recommended to pass this prop if the content deviates too much from the default value. Note that, due to the implementation adopted, the virtualization of the columns is also disabled to force all columns to be rendered at the same time.

<DataGrid getRowHeight={() => 'auto'} getEstimatedRowHeight={() => 200} />
id
username
age
bio
0
@hahbe
42
Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Nam ullamcorper ligula id consectetur auctor. Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Nullam cursus ti 
1
@zoawo
33
Phasellus et ultrices dui. Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Phasellus et ultrices dui. Nulla venenatis justo non felis vulputate, eu mollis metus ornare. 
2
@ziluuce
30
Pellentesque ac metus velit. Phasellus et ultrices dui. Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
3
@mip
20
Nullam cursus tincidunt auctor. Vestibulum in massa nibh. Nam ullamcorper ligula id consectetur auctor. 
4
@ca
41
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ullamcorper ligula id consectetur auctor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et ultrices dui. 
5
@vohosmo
18
Maecenas non felis venenatis, porta velit quis, consectetur elit. Maecenas non felis venenatis, porta velit quis, consectetur elit. Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. 

Rows per page:

1–10 of 10

Row density

Give your users the option to change the default row density to match their preferences—compact, standard, or comfortable. Density is calculated based on the rowHeight and/or columnHeaderHeight props, when present. See Density for details.

Row spacing

You can use the getRowSpacing prop to increase the spacing between rows. This prop is called with a GridRowSpacingParams object.

const getRowSpacing = React.useCallback((params: GridRowSpacingParams) => {
  return {
    top: params.isFirstVisible ? 0 : 5,
    bottom: params.isLastVisible ? 0 : 5,
  };
}, []);
Desk
Commodity
Trader Name
Trader Email
Quantity
D-2475
Soybeans
Caroline Gibbs
6,385
D-3387
Coffee C
Carrie Medina
64,142
D-8411
Rapeseed
Ida Chavez
64,568
D-3051
Frozen Concentrated Orange Juice
Lydia Russell
76,220
D-3166
Corn
Sam Barnett
91,595
D-8226
Cotton No.2
Jorge Chambers
4,108
D-9350
Sugar No.11
Marion Horton
52,846
D-5228
Rapeseed
Corey Patton
36,303

Rows per page:

1–100 of 200

By default, setting getRowSpacing will change the marginXXX CSS properties of each row. To add a border instead, set rowSpacingType to "border" and customize the color and style.

<DataGrid
  getRowSpacing={...}
  rowSpacingType="border"
  sx={{ '& .MuiDataGrid-row': { borderTopColor: 'yellow', borderTopStyle: 'solid' } }}
/>

API