解决layui表格单元格内容换行时设置了fixed的列错位的问题。

问题因为单元格高度被内容撑开,导致fixed的列错位

解决方法

我这是给单元格设置了 文本换行展示高度自动

.layui-table-cell {
        height: auto;
        overflow: visible;
        text-overflow: inherit;
        white-space: normal;
        word-break: break-all;
    }

在表格的done回调里调用函数

done: function (res, curr, count) {

                    admin.adjustTableHeight("w_pyy_mmi_table")

                },

js部分函数

 // 解决表格单元格换行表格错位的方法 2025/03/31 LY

    admin.adjustTableHeight = function (tableId) {

        // 安全处理选择器

        const escapedId = CSS.escape(tableId);

        const $mainTable = $(`#${escapedId}+.layui-table-view`);

        // 错误边界处理

        if (!$mainTable.length) return;

        // 预缓存固定列行集合

        const $fixedRows = $mainTable.find('.layui-table-fixed-r .layui-table-body tr');

        // 同步行高

        $mainTable.find('.layui-table-main tr').each(function (index) {

            const $targetRow = $fixedRows.eq(index);

            if ($targetRow.length) {

                $targetRow

                    .css('visibility', 'visible')

                    .outerHeight($(this).outerHeight());

            }

        });

        // 同步表头高度

        const $mainHeader = $mainTable.find('.layui-table-header:first');

        const headerHeight = $mainHeader.outerHeight();

        const $fixedHeader = $mainTable.find('.layui-table-fixed .layui-table-header');

        $fixedHeader.outerHeight(headerHeight);

        $fixedHeader.find('th').outerHeight(headerHeight);

    }

最后效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值