我们在使用bootstraptable做表格展示时,有时需要固定表格的高度当数据超出高度会出现滚动条,这时有可能出现表头列和数据列对不齐。出现这个问题的原因是数据列出现了滚动条占了宽度,造成表头 数据 的div宽度不一样。
通过Chrome浏览器 f12,看到样式为 .fixed-table-header .fixed-table-body .fixed-table-footer的3个div容器宽度不一样, .fixed-table-header .fixed-table-footer这两个div没有滚动条。
解决方法:
bootstraptable在渲染完列表时会执行onPostBody事件,代码如下。
$('#dataGrid').bootstrapTable({
method: 'post',
url: 'http://www.itxst.com/?ajax',
dataType: "json",
striped: true, //隔行变色
pagination: true, //底部显示分页码
pageSize: 30, //每页显示行数
pageNumber: 1, //页码
pageList: [30, 50, 100, 200, 500], //每页显示数量选择器
idField: "objectId", //主键字段
showColumns: true, //显示隐藏列
showRefresh: true, //刷新按钮
singleSelect: true,
search: false,
clickToSelect: true,
sidePagina