Examples › Scrollable vs. auto-height

Toggle the switch below to see the difference between a scrollable and an auto-height DataTable:

return (
  <DataTable
    height={300}
    // more table props...
  />
);
First name
Last name
Email
Department
Company
Address
City
State
JeraldHowellJerald.Howell32@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
KathleenRueckerKathleen_Ruecker@hotmail.comComputersShanahan, Robel and Beier378 Berta CrescentWest GerryKS
EricaVolkmanErica.Volkman37@gmail.comToysGoyette Inc8873 Mertz RapidDorthysideID
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
AlisonKlingAlison16@gmail.comJeweleryGoyette Inc8873 Mertz RapidDorthysideID
SueZiemeSue.Zieme29@hotmail.comBooksCummerata - Kuhlman6389 Dicki StreamSouth GateNH
FeliciaGleasonFelicia30@yahoo.comShoesDoyle, Hodkiewicz and O'Connell576 Joyce WaysTyraburghKS
AlfredoZemlakAlfredo22@yahoo.comGamesRunte Inc2996 Ronny MountMcAllenMA
EmilyBartolettiEmily.Bartoletti@gmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
DeloresReynoldsDelores.Reynolds@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
LouisSchambergerLouis6@yahoo.comToolsCummerata - Kuhlman6389 Dicki StreamSouth GateNH
BeverlyHellerBeverly_Heller@gmail.comBeautyRunte Inc2996 Ronny MountMcAllenMA
EugeneFeestEugene88@hotmail.comKidsGoyette Inc8873 Mertz RapidDorthysideID
MartinBahringerMartin_Bahringer10@gmail.comBeautyRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
EllisMillerEllis36@hotmail.comElectronicsConnelly, Feest and Hodkiewicz7057 Stanley RoadKearaburghCA
No records

The DataTable component embeds a Mantine ScrollArea and has a default height of '100%'.
Thus, setting the component height or placing it inside a height-restricted container will make it vertically scrollable, with a sticky header. Otherwise, the table simply grows to fit its content.

Using minHeight and maxHeight

Besides height, you can also set minHeight and maxHeight (as numbers in pixels or CSS size strings). They’re particularly useful in combination with a relative height— for instance, the table below takes up half of the browser window height, but never less than 200 and never more than 400 pixels (resize the browser window to see it in action):

<DataTable
  height="50dvh"
  minHeight={200}
  maxHeight={400}
  // more table props...
/>
First name
Last name
Email
Department
Company
Address
City
State
JeraldHowellJerald.Howell32@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
KathleenRueckerKathleen_Ruecker@hotmail.comComputersShanahan, Robel and Beier378 Berta CrescentWest GerryKS
EricaVolkmanErica.Volkman37@gmail.comToysGoyette Inc8873 Mertz RapidDorthysideID
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
AlisonKlingAlison16@gmail.comJeweleryGoyette Inc8873 Mertz RapidDorthysideID
SueZiemeSue.Zieme29@hotmail.comBooksCummerata - Kuhlman6389 Dicki StreamSouth GateNH
FeliciaGleasonFelicia30@yahoo.comShoesDoyle, Hodkiewicz and O'Connell576 Joyce WaysTyraburghKS
AlfredoZemlakAlfredo22@yahoo.comGamesRunte Inc2996 Ronny MountMcAllenMA
EmilyBartolettiEmily.Bartoletti@gmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
DeloresReynoldsDelores.Reynolds@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
LouisSchambergerLouis6@yahoo.comToolsCummerata - Kuhlman6389 Dicki StreamSouth GateNH
BeverlyHellerBeverly_Heller@gmail.comBeautyRunte Inc2996 Ronny MountMcAllenMA
EugeneFeestEugene88@hotmail.comKidsGoyette Inc8873 Mertz RapidDorthysideID
MartinBahringerMartin_Bahringer10@gmail.comBeautyRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
EllisMillerEllis36@hotmail.comElectronicsConnelly, Feest and Hodkiewicz7057 Stanley RoadKearaburghCA
No records

minHeight is also useful to leave enough room for the empty state indicator or the loader when an auto-height table has few or no records.

You can also set a maxHeight without a height: the table will grow with its content and become vertically scrollable once the content exceeds the maximum height.

Customizing the underlying ScrollArea

You can customize the underlying scroll area by passing scrollAreaProps to the DataTable component. It accepts Mantine ScrollArea props such as type, scrollbarSize, scrollHideDelay or offsetScrollbars (except classNames, styles and onScrollPositionChange, which are used internally; to get a reference to the scroll viewport, use the scrollViewportRef property instead of viewportRef). For instance, here’s how you could hide the scrollbars:

<DataTable
  height={300}
  // other props...
  scrollAreaProps={{ type: 'never' }}
/>

Here is the result:

First name
Last name
Email
Department
Company
Address
City
State
JeraldHowellJerald.Howell32@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
KathleenRueckerKathleen_Ruecker@hotmail.comComputersShanahan, Robel and Beier378 Berta CrescentWest GerryKS
EricaVolkmanErica.Volkman37@gmail.comToysGoyette Inc8873 Mertz RapidDorthysideID
CliffordOberbrunnerClifford.Oberbrunner@hotmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
AlisonKlingAlison16@gmail.comJeweleryGoyette Inc8873 Mertz RapidDorthysideID
SueZiemeSue.Zieme29@hotmail.comBooksCummerata - Kuhlman6389 Dicki StreamSouth GateNH
FeliciaGleasonFelicia30@yahoo.comShoesDoyle, Hodkiewicz and O'Connell576 Joyce WaysTyraburghKS
AlfredoZemlakAlfredo22@yahoo.comGamesRunte Inc2996 Ronny MountMcAllenMA
EmilyBartolettiEmily.Bartoletti@gmail.comAutomotiveRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
DeloresReynoldsDelores.Reynolds@yahoo.comIndustrialRunte Inc2996 Ronny MountMcAllenMA
LouisSchambergerLouis6@yahoo.comToolsCummerata - Kuhlman6389 Dicki StreamSouth GateNH
BeverlyHellerBeverly_Heller@gmail.comBeautyRunte Inc2996 Ronny MountMcAllenMA
EugeneFeestEugene88@hotmail.comKidsGoyette Inc8873 Mertz RapidDorthysideID
MartinBahringerMartin_Bahringer10@gmail.comBeautyRau - O'Hara7508 Lansdowne RoadShieldsboroughMI
EllisMillerEllis36@hotmail.comElectronicsConnelly, Feest and Hodkiewicz7057 Stanley RoadKearaburghCA
No records

To react to scrolling, use the onScroll, onScrollToTop, onScrollToBottom, onScrollToLeft and onScrollToRight callbacks (see the infinite scrolling example). To scroll the table programmatically, use the scrollViewportRef property to get hold of the scrollable viewport element (see scrolling a row into view).

Head over to the next example to discover more features.

Mantine DataTable is used and trusted by