You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
The react table example doesn't make the <table> element large enough #585
In the "React Virtual Table Example", the translateY approach to row positioning allows rows to be positioned outside of the <table> element.
This causes issues with at least two things:
A sticky header (<thead style="position:sticky;top:0">) cannot go beyond the bounds of the <table> element
Borders on <tr> elements stop displaying when the <tr> element is outside of the bounds of the <table> element (in Chrome & Firefox)
It's also worth noting that intentionally changing the size of the table causes the rows to become huge, so that doesn't appear to be a solution.
Unless something can be done about the size of the <table> element, it may be best to suggest the padding-rows approach (such as the one used in the "React Table Virtualized Rows Example" in the TanStack Table docs).
Change <thead> to a sticky header (<thead style="position:sticky;top:0">)
Scroll down in the result until the header disappears
Expected behavior
<thead style="position:sticky;top:0"> should remain sticky through the entire table's scrolling.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Windows 11
Browser: Vivaldi 6.2.3105.47
tanstack-virtual version
3.0.0-beta.60
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct
I agree to follow this project's Code of Conduct
I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Reacted by Brian, Guilherme Job, Yannick E., Matthew McCune, Eric P Green, Cédric Dupuis and Mukhammad Osmanov
That example you just provided is using row(s) for padding to keep the <table> element the correct size. However, the example to which I'm referring (https://tanstack.com/virtual/v3/docs/examples/react/table) uses translateY to shift the rows' position in the <table> element, which has the unfortunate side effect of pushing many rows outside of the <table> element's bounds.
It's in the style attribute of the <tr> elements in the <tbody> element:
If the table rows are all fixed height - the calculation for all rows will be the same as the first virtual item.
If the table row height is dynamic, the calculation won't work, but setting all rows to transform to the start of the first virtual item works.
<tbody
css={{
"&::after": {
display: "block",
content: "''",
// this ensures the table takes up as much size as the total elements by adding padding to the end
height: `${ virtualizer.getTotalSize() - virtualizer.scrollRect.height}px`,
},
}}
>
....
</tbody>
Activity
piecyk commentedon Sep 12, 2023
@KOVIKO you can't really position: sticky; on
<thead>checkout https://css-tricks.com/position-sticky-and-table-headers/also for tables better is to avoid the absolute positioning of virtualized items #476
KOVIKO commentedon Sep 12, 2023
That ticket was very useful for knowing the correct way to do the padding-rows approach! Thank you for that!
As far as sticky
<thead>vs sticky<th>is concerned, they still have the same issue with being restricted to the actual<table>element's bounds.If we change the
<th>elements in the example to this, we still get the same issue I mentioned:piecyk commentedon Sep 12, 2023
hmm hard to say what is happening, but sticky should work, here virtualization is not adding anything special, like https://codesandbox.io/s/virtual-simple-table-cdqqpg
KOVIKO commentedon Sep 12, 2023
That example you just provided is using row(s) for padding to keep the
<table>element the correct size. However, the example to which I'm referring (https://tanstack.com/virtual/v3/docs/examples/react/table) usestranslateYto shift the rows' position in the<table>element, which has the unfortunate side effect of pushing many rows outside of the<table>element's bounds.It's in the
styleattribute of the<tr>elements in the<tbody>element:To be clear, this isn't necessarily a bug of
@tanstack/virtual, but rather a bug of the example used in the documentation.piecyk commentedon Sep 12, 2023
Yep, i agree that table examples are misleading, we should not use the absolution positions here.
vojvodics commentedon Oct 30, 2023
@KOVIKO Thanks - your solution worked for me! I'd suggest doing this slightly differently:
If the table rows are all fixed height - the calculation for all rows will be the same as the first virtual item.
If the table row height is dynamic, the calculation won't work, but setting all rows to transform to the start of the first virtual item works.
tboley-vt commentedon Nov 12, 2023
This approach helped me when using
scrollMargin:jmalovera10 commentedon Dec 7, 2023
This worked out for me! I added the
beforeandafterstatements around the virtual items map and set theoverflowAnchortonone.tabarra commentedon Mar 6, 2024
Friendly bump on this issue.
I've wasted a few days trying to get my tables to work only to find out this was the issue.
piecyk commentedon Jul 31, 2025
@tabarra did you try this aproach? #476
rovolution commentedon Feb 20, 2026
@piecyk thank you for posting this!! absolute life saver