BootStrap Table 解决固定表头表头不对应

解决方法

1. 定义每一个表头的固定宽度

2. 在onPostBody中添加次代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

$('#dataGrid').bootstrapTable({
···
···
onPostBody:function()
{
$.each($('.fixed-table-header tr:not(:first-child) .fht-cell'),function(index,obj){
var a=$(obj).parent().attr("style");
var oWidth=a.substring(a.indexOf('width:')+6,a.lastIndexOf(';'));
$(obj).width(oWidth);
});

$.each($('.fixed-table-body tr:not(:first-child) .fht-cell'),function(index,obj){
var a=$(obj).parent().attr("style");
var oWidth=a.substring(a.indexOf('width:')+6,a.lastIndexOf(';'));
$(obj).width(oWidth);
});
}
···
});


核心代码

1
2
3
4
5
6
7
8
9
10
11
$.each($('.fixed-table-header tr:not(:first-child) .fht-cell'),function(index,obj){
var a=$(obj).parent().attr("style");
var oWidth=a.substring(a.indexOf('width:')+6,a.lastIndexOf(';'));
$(obj).width(oWidth);
});

$.each($('.fixed-table-body tr:not(:first-child) .fht-cell'),function(index,obj){
var a=$(obj).parent().attr("style");
var oWidth=a.substring(a.indexOf('width:')+6,a.lastIndexOf(';'));
$(obj).width(oWidth);
});