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"});})}});});