Is there a table component for react, which would have fixed header while browser scrollbar scrolls it's long body? (The table height grows as user clicks "Load more"). Here's a code sample: https://codesandbox.io/s/rm0x6lmypm The table header should remain static on browser scroll.
Asked
Active
Viewed 3.0k times
6
-
first results from google: https://henrybuilt.github.io/react-sticky-table/ , https://react-table.js.org/#/story/readme – Sagiv b.g Aug 11 '18 at 20:16
-
Add your code directly to the question – Zoe Aug 12 '18 at 07:54
-
@Zoe it's ~700 lines of code – Dmitry Stril Aug 12 '18 at 08:05
-
So? You still have to add it to your question, and make an MCVE assuming you haven't already – Zoe Aug 12 '18 at 08:08
-
check out this npm package [react-sticky-table-thead](https://www.npmjs.com/package/react-sticky-table-thead) – Adam Beleko May 19 '20 at 13:26
1 Answers
10
Ok, I have made some horrible css changes, now it seems to work as needed:
https://codesandbox.io/s/18kqoyjq8j
Basically I added styles to react-table
as follows:
.ReactTable {
margin-top: 74px;
}
.ReactTable .rt-tbody {
margin-top: 30px;
}
.ReactTable .rt-thead {
background-color: white;
position: fixed;
top: 1;
z-index: 1;
width: calc(100% - 17px);
height: 31px;
}
So the table header is now fixed under the page header and we can use browser scrollbar to scroll table's body.

Dmitry Stril
- 1,385
- 4
- 16
- 34
-
Sometimes you need to `fake it` as you did :) Sounds like a reasonable workaround – dance2die Aug 12 '18 at 11:26
-
check out this npm package [react-sticky-table-thead](https://www.npmjs.com/package/react-sticky-table-thead) – Adam Beleko May 19 '20 at 13:27
-