【layui】layui.table表格实现底部固定两行合计行

halo,下伙伴们,今天小编记录个关于layui开发的系统,layui.table表格实现底部固定两行(如:本页合计,全部合计)

小编查阅layui文档好像只能设置固定一行,所以就利用js添加css样式来修改它,使其固定两行,那么这两行的数据就需要后端返回,话不多说,上代码:

html 复制代码
<!--样式-->
<style>
        .layui-table-fixed-bottom {
            position: sticky;
            bottom: 0;
            background-color: #f2f2f2;
        }
        .layui-table-fixed-bottom2 {
            position: sticky;
            bottom: 36px;
            background-color: #f2f2f2;
        }
</style>
<!--表格标签-->
<table id="grid" class="layui-hide" lay-filter="grid"></table>
<!--js-->
<script>
	grid = table.render({
            elem: '#grid',
            id:"grid",
            url: '',//你的请求地址
            method:'POST',
            contentType:'application/json;charset=UTF-8',
            where:{},//请求参数
            cols:cols,
            page: {limit: 20 },
            // 将底部两行固定在底部
            done: function() {
                var tableContainer = document.querySelector('.table-container');
                var lastRows = tableContainer.querySelectorAll('.layui-table-body tbody tr:last-child');
                if (lastRows.length > 1) {
                    lastRows[lastRows.length - 2].classList.add('layui-table-fixed-bottom');
                    lastRows[lastRows.length - 1].classList.add('layui-table-fixed-bottom');
                    //修改第二列的文本
                    lastRows[1].childNodes[1].innerText = '所有合计'
                    lastRows[0].childNodes[2].innerText = '--'
                    lastRows[0].childNodes[lastRows[0].childNodes.length-1].innerText = '--'
                }
                var lastRows2 = tableContainer.querySelectorAll('.layui-table-body tbody tr:nth-last-child(2)');
                if (lastRows2.length > 1) {
                    lastRows2[lastRows2.length - 2].classList.add('layui-table-fixed-bottom2');
                    lastRows2[lastRows2.length - 1].classList.add('layui-table-fixed-bottom2');
                    lastRows2[1].childNodes[1].innerText = '本页合计'
                    lastRows2[0].childNodes[2].innerText = '--'
                    lastRows2[0].childNodes[lastRows2[0].childNodes.length-1].innerText = '--'
                }
            }
        });
</script>

好啦,以上是用layui.table渲染完成后对行列进行js来添加样式和修改标签文案的,如果小伙伴们有其他方法麻烦在下方评论告诉下小编哦~

相关推荐
云水一下3 小时前
Vue.js从零到精通系列(三):组件化基础——Props、Emits、插槽与生命周期
前端·javascript·vue.js
小糯米6013 小时前
JavaScript表达式与运算符
开发语言·javascript·ecmascript
体验家4 小时前
体验家 XMPlus 网页端问卷 SDK 技术解析:用几行 JavaScript 实现精准场景触发与防打扰机制
开发语言·前端·javascript
VidDown4 小时前
VidDown 工具站:视频分辨率技术
javascript·网络·编辑器·音视频·视频编解码·视频
小鹿软件办公4 小时前
倒计时开启:Chromium 宣布几周内将全面切断 MV2 扩展支持
开发语言·javascript·ublock origin
Csvn5 小时前
TypeScript:你以为安全的 `JSON.parse` 其实是颗雷 — 运行时类型安全实战
前端·javascript
触底反弹5 小时前
从 JS 引擎执行原理理解数据类型:栈内存、堆内存与作用域
javascript·数据结构·面试
橘子星5 小时前
深入理解线性数据结构:栈、队列与链表
前端·javascript
Larcher5 小时前
JS 数据类型的八重人格与内存真相
前端·javascript
Maimai108085 小时前
Web3 前端实时通信如何落地:从 SSE 订阅到行情、订单与账户状态更新
前端·javascript·react.js·前端框架·web3·状态模式