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

相关推荐
Geoffwo3 分钟前
robotjs0.6.0鼠标中轴滚动失效修复方案
前端·javascript
溪语流沙42 分钟前
【Web全栈进阶】Vue Router + Pinia:SPA路由与全局状态
前端·javascript·vue.js
兰亭妙微UI设计公司1 小时前
兰亭妙微软件界面设计公司的解锁按钮设计10大密码
开发语言·前端·javascript
u0111026752 小时前
WebP 转成 PNG 后为什么更大?图片格式转换不等于压缩
前端·javascript·vue.js
小皮虾2 小时前
小程序全局状态还能这么简单?只需初始化一次,页面自动同步
前端·javascript·微信小程序
daols883 小时前
vue 甘特图组件 vxe-gantt 修改滚动条样式-让滚动条自动隐藏
javascript·vue.js·甘特图
今年下半年4 小时前
【前端】Vue2 项目 ECharts 统计图表组件封装与使用实践(附组件源码)
前端·javascript·echarts
冒险的豆子4 小时前
JS 原型链 通俗易懂 解释说明(类比 关系)
开发语言·javascript·原型模式
西索斯coding4 小时前
在 中接入 教程:p配置、m填写、扩展思考参数一篇就够(2)
java·前端·javascript·ai
用户1733598075374 小时前
纯前端 PDF 双面打印避坑指南:翻页顺序错了整个白印?
前端·javascript·vue.js