Skip to content

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

Closed
@muubar

Description

@muubar

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions