-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Table headers are not aligned with its content. #6006
Comments
Can you reproduce the problem? https://live.bootstrap-table.com/code/wenzhixin/10049 |
Love this library too. Did anyone find a fix for this yet? I'm seeing this same issue with the table header columns not aligned correctly as well. This appears to be related to having a 'height' value on the table which causes the table-body to scroll and the headers to become fixed in place and not scroll out of view. Which is the exact UX we are after. With no height value on the table, the columns and headers look normal. Example: Much appreciated. |
I found a little trick to temporarily solve the problems. |
As @ryan-kite pointed out that the issue is caused by the virtual scrollbar. The table header has the full width of the tableContainer, while the tableBody is padded by the scrollbar. To fix this, I overrode the resetView function and added the following to add padding to the tableHeader to account for the scrollbar. If the scrollbar isn't present then headerPadding should be 0.
Edited:
|
@tvargas1 where are you adding in that code to fix the issue, I can't seem to get it working as expected. |
Add the following after the bootstrap-table script tag like this:
Because bootstrap table initializes on document ready it should apply to data-toggle="table" as well as programmatically initialized tables. I'm also using additional extensions and have not run into any problems. Hope this helps. One last thing, if you are using max-width css on any of the columns that can interfere with proper alignment. I ran into this problem coming from a base template. I believe it would need to be applied to both td and th of the column if you are using it, but I haven't tested this. |
@tvargas1 - That worked! I did have max-width on one column, but it didn't seem to impact the result. Thank you for the help. |
Please be cautious about using the workaround posted by @tvargas1 above. It will break certain other features in bootstrap-table, including the filter-control extension and export button. |
@dougauerbach you are correct. I didn't use these extensions in my original implementation. It looks like there may have been a fix in 1.20.0 but I haven't checked it out yet. https://github.com/wenzhixin/bootstrap-table/releases/tag/1.20.0 If that doesn't work or you are on an older version this change seem to resolve the issues, but I haven't fully tested it. Basically place the extend right below bootstrap-table js and move super.resetView(params); to the bottom of the function. <script src="https://unpkg.com/[email protected]/dist/bootstrap-table.min.js"></script>
<script>
// fix for misaligned column headers
// https://github.com/wenzhixin/bootstrap-table/issues/6006
$.BootstrapTable = class extends BootstrapTable {
resetView(params) {
let $bodyTable = this.$tableBody.find('>table')
let headerPadding = this.$tableContainer.innerWidth() - $bodyTable.innerWidth()
this.$tableHeader.css('padding-right', `${headerPadding}px`)
super.resetView(params);
}
}
</script>
<script src="https://unpkg.com/[email protected]/dist/extensions/export/bootstrap-table-export.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/extensions/filter-control/bootstrap-table-filter-control.min.js"></script> hope this helps |
Can't reproduce this issue in the latest version. |
I found when using table.height option, if the content has vertical scrollbar, the table header will not align with the table body (content). I found the code here may has problem: var scrollWidth = this.hasScrollBar && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0; |
@UtechtDustin I am able to reproduce the same issue , here are the steps I followed to reproduce it:
|
|
I use Chrome 114.0.5735.199 |
I have observed the issue also in the offical documentation on the page |
Still an issue in 1.23.1. As @svobtom pointed out, it can be observed in the examples on the bootstrap-table website https://examples.bootstrap-table.com/index.html?bootstrap5#extensions/sticky-header.html |
@UtechtDustin the issue doesn't happen unless you're using Sticky Headers and you've scrolled down with the header off the screen. |
dup #7090 |
Description
First, thank you for the great project.
I'm having problem that the table headers are not aligned with its content.
With the same data, this problem sometimes occurs, and it will be disappear with I click to any headers which have the sorting function.
Could you tell me which one I'm doing wrong? Thank you.
By the way, I'm new with this so please let me know if there are anything inappropriate.
Example(s)
Hear is my example:
https://live.bootstrap-table.com/code/nobleboyh/10042
*I'm using lastest Chrome browser.
The text was updated successfully, but these errors were encountered: