使用bootstrap-table的时候,有时发现表头与数据不对齐的问题,特别是列很多或者浏览器有缩放时比较明显。
查看源码bootstrap-table.js你会发现,表头是根据tbody的第一行的每一个元素的innerWidth()来定宽度的,然而检查元素发现,innerWidth()总取整数,而忽略的实际的小数点,导致列越多,表头偏移得越明显,修改源码(将innerWidth()用getBoundingClientRect().width来代替即可,大概是1528和1537行左右):
e.prototype.fitHeader = function () {var t = this, u, r, x, y;if (t.$el.is(":hidden")) {t.timeoutId_ = setTimeout(j.proxy(t.fitHeader, t), 100);return}u = this.$tableBody.get(0);r = u.scrollWidth > u.clientWidth && u.scrollHeight > u.clientHeight + this.$header.outerHeight() ? a() : 0;this.$el.css("margin-top", -this.$header.outerHeight());x = j(":focus");if (x.length > 0)