【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来添加样式和修改标签文案的,如果小伙伴们有其他方法麻烦在下方评论告诉下小编哦~

相关推荐
cc蒲公英42 分钟前
javascript有哪些内置对象
java·前端·javascript
zhangwenwu的前端小站1 小时前
vue 对接 Dify 官方 SSE 流式响应
前端·javascript·vue.js
AY呀2 小时前
# 🌟 JavaScript原型与原型链终极指南:从Function到Object的完整闭环解析 ,深入理解JavaScript原型系统核心
前端·javascript·面试
氤氲息2 小时前
鸿蒙 ArkTs 的WebView如何与JS交互
javascript·交互·harmonyos
小皮虾2 小时前
护航隐私!小程序纯前端“证件加水印”:OffscreenCanvas 全屏平铺实战
前端·javascript·微信小程序
叫我詹躲躲2 小时前
Vue 3 动画效果实现:Transition和TransitionGroup详解
javascript·vue.js
叫我詹躲躲2 小时前
别再用mixin了!Vue3自定义Hooks让逻辑复用爽到飞起
javascript·vue.js
豆苗学前端2 小时前
HTML + CSS 终极面试全攻略(八股文 + 场景题 + 工程落地)
前端·javascript·面试
珑墨2 小时前
【迭代器】js 迭代器与可迭代对象终极详解
前端·javascript·vue.js
Fantastic_sj3 小时前
[代码例题] var 和 let 在循环中的作用域差异,以及闭包和事件循环的影响
开发语言·前端·javascript