产生原因:
bootstrap table 固定表头后不对齐
在bootstrap table 插件中添加data-height属性后,表格就是固定表头效果,但是在有这个效果后会有小的瑕疵,表头和表格的线不对齐,
这个时候页面上存在两个table,
fixed-table-header 中存在这个这个table ,只展示表头
fixed-table-body 中存在这个table,又重复展示了一次表头内容,再加上表体内容
fixed-table-header与fixed-table-body存在table中的th 宽度不一致造成的
我的解决方案:
重新设置每一个table宽度:
重新写了一个方法,来处理宽度,直接在table渲染完成之后调用此方法即可
//固定表头错位方法,此处tableId 为fixed-table-body元素中table的id。目的是为了定位处理th使用
function dislocation(tableId){
$("#"+tableId).parent().children().find("thead tr th").each(function(){
$(this).width(Math.floor($(this).width()))
})
$("#"+tableId+" thead tr th").each(function(){
$(this).width(Math.floor($(this).width()))
})
$("#"+tableId+" tbody tr:first td").each(function(i,item){
$(this).width(Math.floor($(this).width()))
})
}
屏幕分辨率变化时,处理办法:
$(window).resize(function(){
var body = document.getElementsByClassName("fixed-table-body")[0];
if(body==undefined){
return;
}
$(body).children().bootstrapTable('resetView');
})
以上是我的方案,欢迎指正