springboot + layui + pageHepler 实现table 表格分页并且多行小计功能

日常表格统计中我们会用到总计的功能,这个功能layui帮我们已经实现了,

但有时候我们也需要在某个业务类型上,实现小计功能:

由于pageHepler的介入,导致我们没办法在数据传到前端的时候进行小计数据的插入,只能通过前端加载完数据后进行渲染,使用到的是table.render 中的done()方法。

具体实现代码:

javascript 复制代码
table.render({
            elem: '#schoolInfo-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#schoolInfo-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports'],
            done: function(res,curr,count){
                console.log(res.data);
                var that = this.elem.next();
                var c1 = 0;
                var c2 = 0;
                res.data.forEach(function(item,index){
                    //寻找到当前行
                    var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']");
                    console.log(item.teacherWxCode)//获取当前行的某一列的值,这里只是展示作用
                    console.log(tr);
                    

                    if((index+1)%2==0){
                        //要插入的小计数据的行信息
                        var newhtml = '<tr>' +
                            '<td></td>' +
                            '<td></td>' +
                            '<td></td>' +
                            '<td></td>' +
                            '<td></td>' +
                            '<td>小计:</td>' +
                            '<td></td>' +
                            '<td style="text-align: center">'+c1+'</td>' +
                            '<td style="text-align: center">'+c2+'</td>' +
                            '<td></td>' +
                            '<td></td>' +
                            '</tr>';
                         tr.after(newhtml);
                        c1 = 0;
                        c2 = 0;
                    }else{
                        c1++;
                        c2++;
                    }

                })
            }
        });
相关推荐
shejizuopin5 分钟前
基于Spring Boot的高校科研管理系统的设计与实现(毕业论文)
java·spring boot·vue·毕业设计·论文·毕业论文·高校科研管理系统的设计与实现
indexsunny6 分钟前
互联网大厂Java面试实战:Spring Boot微服务在电商场景中的应用
java·数据库·spring boot·redis·微服务·kafka·电商
哪里不会点哪里.12 分钟前
如何自定义一个 Spring Boot Starter?
java·spring boot·后端
不吃香菜学java19 分钟前
springboot左脚踩右脚螺旋升天系列-入门程序
java·spring boot·后端
悟能不能悟30 分钟前
eclipse run springboot的application类,保存文件的路径会默认在哪里
java·spring boot·eclipse
没有bug.的程序员32 分钟前
Spring Boot 性能优化:启动时间从 5s 到 1s 的全链路实战指南
java·spring boot·后端·spring·性能优化·全链路·启动时间
Sweet锦39 分钟前
无需JVM!GraalVM打造Windows平台零依赖Java应用
java·windows·后端·云原生·开源
colicode43 分钟前
java短信接口开发对接全流程:Spring Boot项目集成短信功能详解
java·开发语言·spring boot
csdn_aspnet1 小时前
Go语言常用算法深度解析:并发与性能的优雅实践
后端·golang·go
SamRol1 小时前
达梦数据库指令 及 在Spring Boot + MyBatis-Plus上的使用
java·数据库·spring boot·mybatis·达梦·intellij idea