解决方案是找到bootstrap-table.js中的 BootstrapTable.prototype.resetView方法,将如下代码注掉:(实践发现,以上解决方案如果将窗口缩小时还是会错位)
if (this.options.showHeader && this.options.height) {
this.$tableHeader.show();
//注释掉下面两行 取消表头初始化解决表头和内容不对齐问题
// this.resetHeader();
// padding += this.$header.outerHeight();
} else {
this.$tableHeader.hide();
this.trigger('post-header');
}
如果你的表格数据是固定行(即不存在表头固定的需求设定,如数据量固定为10行)则可以使用以下方案,即将header表头隐藏,然后原始表头去掉偏移量即可
.fixed-table-header table{display: none}
.fixed-table-body table {margin-top:0px !important;}