react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Wrong header items width

Open jdelafon opened this issue 10 years ago • 28 comments

The table header's width is not calculated the same way as the table's body, ending up in situations like this (note the header overflowing on the right):

capture d ecran 2016-10-19 08 50 07

[Edit: actually it happens even without this, see below] It happened because the bar on the left appears after a transition, and the whole layout re-rendered accordingly but the header did not.

[Edit: just missing CSS files] Also probably related: the width of a menu item is calculated before the sorting arrows are placed, which can produce this:

image

I could solve this by setting the width property, but I don't want fixed with, and no minWidth prop is available.

jdelafon avatar Oct 19 '16 06:10 jdelafon

@jdelafon, first of all, you forgot to add the css of react-bootstrap-table. you can find it under the dist folder. If the problem still there, feel free to tell me :)

AllenFang avatar Oct 19 '16 13:10 AllenFang

Indeed, thanks, it works now. I naively thought npm would do that, but I had to add it to the webpack config entry points.

jdelafon avatar Oct 19 '16 13:10 jdelafon

Actually with the CSS added there is still an issue: instead of being shifted, one header item completely disappeared. If I remove the side bar, it works fine.

2016-10-19_16-02-55

Redimensioning the window fixes it, but after each page reload the last item disappears. So there is still a refresh missing somewhere.

jdelafon avatar Oct 19 '16 14:10 jdelafon

And this is with a classic 2-columns layout, no more animation, no added css. : the column headers are misplaced (N.B. overflow: hidden):

Small window size: 2016-10-19_20-57-28

Large window size: 2016-10-19_20-57-50

Edit: For some reason, according to changes I can make in dev tools, if there was no "width" not "min-width" properties to the th element, it would work just fine.

Edit: And it is written in the "style" prop instead of in the CSS of a class, which makes it untouchable. I think a flexbox design would do that just fine, too.

It gets fixed when I just resize the window, but breaks again on page reload.

jdelafon avatar Oct 19 '16 15:10 jdelafon

For some reason, according to changes I can make in dev tools, if there was no "width" not "min-width" properties to the th element, it would work just fine.

you means no any width or min-width on <TableHeaderColumn>?

And it is written in the "style" prop instead of in the CSS of a class, which makes it untouchable. I think a flexbox design would do that just fine, too.

Sorry, I cant get you, any example or detail explanation?

BTW, what's browser and version you use? if you use newest chrome, there's known unalign issues.

if you can, maybe a repo give me to reproduce this issue is good, sometimes, this unalign problems is hard to reproduce on my local.

Thanks :)

AllenFang avatar Oct 20 '16 12:10 AllenFang

I tried the latest Chrome and Firefox. I had to remove both width and min-width to get a normal layout in Chrome devtools, "element.style" section. I meant that using the new flexbox CSS properties, these sizing issues may go away. I will try to make an minimal example but it will take some time.

jdelafon avatar Oct 20 '16 12:10 jdelafon

that's ok, take your time. I'll keep to figure out

AllenFang avatar Oct 20 '16 13:10 AllenFang

Here is a short part of my app reproducing the issue.

Archive.zip

The archive contains a complete project. Run "npm install", then "node run start" and go to localhost:3000.

I fail to understand what is special in this example, because I saw it happen without this react-sidebar component, but I can't reproduce yet. But at least it should point out differences between the body rows and the menu row with respect to layout.

2016-10-20_16-04-43

The root component is in /pages/projects/index.js and the sidebar in /components/Layout/Sidebar/Sidebar.js.

jdelafon avatar Oct 20 '16 14:10 jdelafon

@jdelafon, thanks you 👍

AllenFang avatar Oct 23 '16 03:10 AllenFang

Hey @AllenFang @jdelafon, I'm also having a similar issue. I've included the CSS, but it seems the issue is in the JS calculation of widths (it sets inline styles).

The widths are wrong: image

Here's what my table looks like: image

thienanle avatar Oct 23 '16 03:10 thienanle

@thienanle, what's your browser and version? any simple repo for me to reproduce this issue? Thanks

AllenFang avatar Oct 23 '16 05:10 AllenFang

@AllenFang I'll set something up. I'm on Chrome version 54.0.2840.71 (64-bit)

May be useful information: when I resize my browser, the widths get re-calculated correctly.

thienanle avatar Oct 23 '16 05:10 thienanle

Ah my mistake, it's happening to me because I didn't include the bootstrap css file. Probably unrelated to OP's issue.


edit: still having the issue after adding bootstrap css, it is the same issue as OP's.

thienanle avatar Oct 23 '16 08:10 thienanle

@jdelafon We have the same setup (using React Static Boilerplate). It seems the issue stems from the CSS being applied after JS runs. JS runs in order to calculate header item widths, and since the CSS hasn't been applied yet, it calculates the wrong widths.

I believe this isn't an issue with react-bootstrap-table, but with our setup or perhaps React Static Boilerplate.

thienanle avatar Oct 23 '16 14:10 thienanle

@thienanle Good point. But I'd argue that since we can make every other component work, including the table's body itself, why should the table's header not scale correctly?

Isn't the CSS always applied after, especially with css-modules/postcss?

jdelafon avatar Oct 23 '16 14:10 jdelafon

@jdelafon The table body doesn't have any widths applied to it from JS (at least in my setup). It is dynamically sized per the default behavior of HTML tables.

CSS isn't always applied after. I think this has something to do with webpack's loading of modules. From what I know, the chunks all load asynchronously, so there's no way to know if the CSS loads before or after. I think switching the CSS loading to synchronous should solve our issue.

thienanle avatar Oct 24 '16 02:10 thienanle

@thienanle That suggests that there is a way to calculate proper widths without JS, among which the now all-browsers-compatible CSS3 "flexbox", or a "display: table/table-row/table-cell" pattern. I am quite sure that Facebook's "fixed-data-table" module uses flexbox for that.

jdelafon avatar Oct 24 '16 05:10 jdelafon

@thienanle, you are right, react-bootstrap-table will calculate and set the width on column for aligning header and body(Actually, header and body are two separate tables).

@jdelafon, yes, there's some people who suggest me to use flexbox, but base on Bootstrap, I need to study more to think about how to use flex with bootstrap.

BTW, because I want to make the vertical and horizontal scroll available on bootstrap table, I just make a table as two separated table for header and body, so I need the other effort to align them.

so if any idea or any simple html + css to implement bootstrap table with scrollable, feel free to discuss with me :)

AllenFang avatar Oct 24 '16 12:10 AllenFang

Forgot something, you said you use React Static Boilerplate and cause this problem, but why and where's make this unalign issue?

AllenFang avatar Oct 24 '16 12:10 AllenFang

@AllenFang

It seems the issue stems from the CSS being applied after JS runs. JS runs in order to calculate header item widths, and since the CSS hasn't been applied yet, it calculates the wrong widths.

It's not necessarily the boilerplate's issue, but the way webpack loads the modules. I think since they're all loading asynchronously, there's no guarantee that CSS loads before JS.

thienanle avatar Oct 24 '16 22:10 thienanle