使用版本
version: 1.16.0
https://github.com/wenzhixin/bootstrap-table/
解决方案
直接上代码
百度、google了一圈之后发现一般都是两种方案
- 更改源码
if (this.options.showHeader && this.options.height) {
this.$tableHeader.show();
//注释掉下面两行 取消表头初始化解决表头和内容不对齐问题
//this.resetHeader();
//padding += this.$header.outerHeight();
}
直接更改源码好像有缺陷,不能固定表头(有待验证)。
2. 使用 onPostBody
原因分析这里我就不贴了,可以参考https://www.jb51.net/article/165716.htm
别人的代码
onPostBody:function()
{
//重点就在这里,获取渲染后的数据列td的宽度赋值给对应头部的th,这样就表头和列就对齐了
var header=$(".fixed-table-header table thead tr th");
var body=$(".fixed-table-header table tbody tr td");
var footer=$(".fixed-table-header table tr td");
body.each(functio