layui table设置表格单元格换行,固定列高度改变

layui table设置表格单元格换行

css

/** 控制表格单元格换行 **/
.layui-table-cell {
	height: auto;
	word-break: normal;
 	display: block;
 	white-space: pre-wrap;
 	word-wrap: break-word;
 	overflow: hidden;
}

js

layui.use('table', function(){
	var table = layui.table;
	table.render({
		done: function(res, curr, count){
			var tableView = this.elem.next();
			//控制将表格的列拉伸时,固定列的也会同时将高度改变
			var bodyTrList = $(".layui-table-main tbody tr");
			for (var i = 0; i < bodyTrList.length; i++) {
				var trEle = bodyTrList[i];
				var dataIndex = trEle.getAttribute("data-index");
				var offsetHeight = trEle.offsetHeight;
				$("div[lay-id='initTable'] .layui-table-fixed tr[data-index='" + dataIndex + "']").css({height: offsetHeight + "px"});
			}
			$(".layui-table-body tbody tr").resize(function (e) {
				var dataIndex = e.currentTarget.getAttribute("data-index");
				var offsetHeight = e.currentTarget.offsetHeight;
				$("div[lay-id='initTable'] .layui-table-fixed tr[data-index='" + dataIndex + "']").css({height: offsetHeight + "px"});
			})
			$("div[lay-id='initTable'] .layui-table-header:first tr").resize(function (e) {
				var dataIndex = $(this).index();
				var offsetHeight = this.offsetHeight;
				$("div[lay-id='initTable'] .layui-table-fixed thead tr").eq(dataIndex).css({height: offsetHeight + "px"});
			})
		}
	});
});


 

 

    原文作者:glgom
    原文地址: https://blog.csdn.net/glgom/article/details/106661644
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞