老项目用到了 jqGrid表格 当中如果使用了冻结表格后 会出现高度不一致的情况
解决办法是通过表格渲染完成后 手动进行同步高度 代码改动最小也最方便
错行前效果:
function resetTableHeight(tableId) {
// 修改后单个表格高度
jQuery(tableId + ' tr').slice(1).each( function (index, element) {
jQuery(element).css('height', '')
const id = jQuery(element).attr('id')
if (!id) return
// 是否有冻结表格
if (jQuery(tableId + '_frozen tr' ).eq(id).length > 0) {
// 获取任意一边的高度
const height = jQuery(element).outerHeight(true)
// 进行双向同步高度
jQuery(element).css('height', height)
// 判断是否是最后一个
if (jQuery(tableId + ' tr').slice(1).length > 7 && index+1 == jQuery(tableId + ' tr').slice(1).length) {
// TODO:有些表格最后结尾的高度可能会出现一像素的差距所以 最后一个表格高出一像素 抵消底边框多余高度
jQuery(tableId + '_frozen tr' ).eq(id).css('height', height + 1)
} else {
// 进行双向同步高度
jQuery(tableId + '_frozen tr' ).eq(id).css('height', height)
}
}
})
}
解决后效果:
在 loadComplete
中调用当前方法 在resizeStop
中调用