Skip to content
Advertisement

React Material-Ui Sticky Table Header with Dynamic Height

I am using the Material-UI framework for React to display a table. I would like to use a sticky header; however, I do not want to set a height on my table, as I’d like it to scroll with the page. The following snippet does not stick the header unless I set a height on the TableContainer.

https://codesandbox.io/s/winter-firefly-5wlx2?file=/src/App.js

JavaScript

Advertisement

Answer

Get rid of the TableContainer overflow-x: auto and it should work

JavaScript

Edit cool-shadow-59lrh

Reference: https://css-tricks.com/dealing-with-overflow-and-position-sticky/

Advertisement