Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabling fixedHeader and having columns with dynamic width causes the table header row to be misaligned with the body rows #422

Closed
muubar opened this issue Jan 10, 2020 · 7 comments · Fixed by #874
Assignees
Labels
enhancement New feature or request

Comments

@muubar
Copy link

muubar commented Jan 10, 2020

First of all, thank you for the great effort, I've been using RDT at work for a while now, so again, thank you.

Describe the bug

when I enable fixedHeader the table body is set to have overflow-y: scroll, which will always show the vertical scrollbar, this is a correct behavior, however, this causes the content width of the header row to be larger than the content width of body rows, this happens because the scrollbar is taking up space from the table body row as well.
this starts to be a problem if I have grow: '1' on some of my columns, which means we now have column's with dynamic width, but now the width of the column head is no longer equal to the cells width under the same column, because again, the overall width of the header row is larger than the width of the body row.
this whole issue can be simply solved by adding padding-right: SCROLLBAR_WIDTH to the header row.

To Reproduce

Steps to reproduce the behavior:

  1. add columns with width only, and others with minWidth and grow, and have fixedHeader enabled
  2. fill the headers with any data, and do the same for the body
  3. notice how the columns with dynamic width are not aligning correctly with the body below them

Expected behavior

I expect each column header to align correctly with the cells in the body that are under the same column

Code Sandbox

https://codesandbox.io/s/react-data-table-sandbox-2m8l9

Screenshots

1)

row sample

2)

header sample with no padding

3)

header sample with padding fix

Versions

  • React: 16.8.6
  • Styled Components: 4.4.0
  • OS: windows 10
  • Browser: Chrome
  • Version: 79.0.3945.88
@jbetancur jbetancur self-assigned this Jan 10, 2020
@jbetancur
Copy link
Owner

jbetancur commented Jan 10, 2020

You're welcome! I'll have a look at this. I will be completely honest in that the fixedHeader feature is not feature complete so it could use some TLC

@muubar
Copy link
Author

muubar commented Jan 11, 2020

@jbetancur I think you might find using this hook useful if you decide to fix it the way I suggested, another solution I was thinking of is to wrap the table body inside a div, and let that div have a height that is equal to the table body's height, and then let this new div handle the overflowing content with a scrollbar, this way the scrollbar will be right outside the body of the table instead of inside of it; something like this

@jbetancur
Copy link
Owner

@muubar I think I like the idea of enhancing the existing TableWrapper do to this so the scroll bar is outside of the entire table. Then, using position sticky on the table header. The only obvious issue, of course, is that IE11 users can't use fixedHeader, but I think that's fine

@jbetancur jbetancur added the enhancement New feature or request label Jan 31, 2020
@sjbr
Copy link

sjbr commented Aug 20, 2020

if I add padding-right to the headrow the leftmost colums are misaligned to the left. So that workaround doesn't fix the issue for me

@danspyer
Copy link

danspyer commented Dec 23, 2020

@jbetancur Would you mind if I submitted a pull request to make the table header utilise the sticky positioning? We've been using this component at my workplace and I've already done this but utilising the css classes to change the behavior.

@jbetancur
Copy link
Owner

I finally have a fix for this. It will be available in v7.0.0-rc6 sometime today or latest this week.

@jbetancur
Copy link
Owner

@danspyer I did not hear back from you on the PR you submitted #737 so it auto closed, but just wanted to call out that some of what you suggested is being implemented here just on the ResopnsiveWrapper and along with some refactor that was originally in the scope of your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants