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-7140
Rough Rice
Steven Meyer
15,669
D-3149
Frozen Concentrated Orange Juice
Lura Ellis
39,097
D-3059
Oats
Bernice Chandler
26,285
D-4087
Adzuki bean
Nancy Chambers
83,285
D-4387
Coffee C
Ronald Bates
18,899
D-9974
Corn
Lawrence Ryan
35,505
D-7075
Adzuki bean
Chester Boone
18,213
D-9961
Rough Rice
Cynthia Martinez
85,345
D-7605
Frozen Concentrated Orange Juice
Florence Huff
95,517
D-7432
Soybeans
Lina Perez
27,626
D-8017
Sugar No.11
Barry Ingram
78,656
D-7078
Soybeans
Janie Carr
58,673
D-496
Milk
Lillian Dawson
73,254
D-4334
Robusta coffee
Jack Ortiz
35,048
D-4286
Wheat
Theodore Burns
56,683

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
@tobfu
65
2
@owkiseg
11
3
@evetog
15
4
@maudu
18
5
@lomvulut
19

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
@huupiku
79
Fusce facilisis egestas massa, et eleifend magna imperdiet et. Nullam cursus tincidunt auctor.
1
@wop
46
Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Vestibulum in massa nibh.
2
@fajsetuf
43
Nullam cursus tincidunt auctor. Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet.
3
@awpuhju
25
Fusce facilisis egestas massa, et eleifend magna imperdiet et. Nullam cursus tincidunt auctor.
4
@ki
57
Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Maecenas non felis venenatis, porta velit quis, consectetur elit. Pellentesque ac metus velit. Nulla venenatis justo non felis vulputate, eu mollis metus ornare.
5
@curju
77
Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Fusce facilisis egestas massa, et eleifend magna imperdiet et.
6
@ufnik
71
Phasellus et ultrices dui. Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a.
7
@hov
34
Nam ullamcorper ligula id consectetur auctor. Fusce facilisis egestas massa, et eleifend magna imperdiet et. Aliquam dapibus, lorem vel mattis aliquet, purus lorem tincidunt mauris, in blandit quam risus sed ipsum.

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
@feoga
69
Pellentesque ac metus velit. Fusce facilisis egestas massa, et eleifend magna imperdiet et. Aliquam dapibus, lorem vel mattis aliquet, purus lorem tincidunt mauris, in blandit quam risus sed ipsum. Fu 
1
@womcupo
17
Phasellus et ultrices dui. Pellentesque ac metus velit. Nulla venenatis justo non felis vulputate, eu mollis metus ornare. Vestibulum commodo et odio a laoreet. 
2
@opivumna
19
Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Pellentesque ac 
3
@kizopvec
42
Fusce facilisis egestas massa, et eleifend magna imperdiet et. Sed feugiat venenatis nulla, sit amet dictum nulla convallis sit amet. Aliquam dapibus, lorem vel mattis aliquet, purus lorem tincidunt m 
4
@edir
15
Aliquam dapibus, lorem vel mattis aliquet, purus lorem tincidunt mauris, in blandit quam risus sed ipsum. Maecenas non felis venenatis, porta velit quis, consectetur elit. Nam ullamcorper ligula id co 
5
@dispuiv
76
Vestibulum pulvinar aliquam turpis, ac faucibus risus varius a. Nam ullamcorper ligula id consectetur auctor. Phasellus et ultrices dui. Phasellus et ultrices dui. 

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-9246
Soybeans
Derrick Davidson
46,091
D-6648
Sugar No.14
Elizabeth Thornton
67,637
D-9483
Soybean Oil
Billy Singleton
90,571
D-5533
Cotton No.2
Adele Frank
6,334
D-6916
Sugar No.11
Alvin Conner
52,204
D-3942
Oats
Erik Robbins
26,845
D-8093
Corn
Blake Turner
86,941
D-2238
Sugar No.11
Clyde Holloway
91,699

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