首页 > 其他分享 >layUI数据表格实现合计 方式一

layUI数据表格实现合计 方式一

时间:2023-03-07 12:14:16浏览次数:42  
标签:表格 title true layUI field layui table 合计 data

方式:后台获取合计数据

 1 //渲染表格
 2         var renderTable = function () {
 3             table.render({
 4                 elem: '#eatInfoTable',
 5                 url: '请求路径',
 6                 height:'full-170',
 7                 toolbar: '#toolbarDemo',
 8                 where: {},
 9                 cellMinWidth: 100,
10                 page: true,
11                 limit:15,
12                 totalRow: true,
13                 cols: [[
14                     {field: 'sData',  title: '日期',totalRowText: '合计'},
15                     {field: 'breakfastPNum',  title: '早餐人数',totalRow: true},
16                     {field: 'breakfastAmount',  title: '早餐金额(元)',totalRow: true},
17                     {field: 'chineseFoodPNum',  title: '午餐人数',totalRow: true},
18                     {field: 'chineseFoodAmount',  title: '午餐金额(元)',totalRow: true},
19                     {field: 'dinnerPNum',  title: '晚餐人数',totalRow: true},
20                     {field: 'dinnerAmount',  title: '晚餐金额(元)',totalRow: true},
21                     {field: 'takeoutPNum',  title: '其它消费人数',totalRow: true},
22                     {field: 'takeoutAmount',  title: '其它消费金额(元)',totalRow: true},
23                     {fixed: 'right', width: 180, align: 'center', title: '操作' ,totalRow: true, templet:function(d){
24                     var html = '<a class="layui-btn layui-btn-sm bg-white hover-blue" lay-event="show">查看明细</a>';
25 
26                     return html;
27                     }}
28 
29                 ]],done:function(res){
30                     $("#totalNum").html(res.count);
31                     //合计
32                     let that=this;
33                     var userType = $("#userType").val();
34                     var queryDate = $("#queryDate").val();
35                     $.get("合计数据请求路径",{userType,queryDate},function (data){
36                         that.elem.next().find('.layui-table-total td[data-field="breakfastPNum"] .layui-table-cell').text(trunc(data.datas.breakfastPNumCount));
37                         that.elem.next().find('.layui-table-total td[data-field="breakfastAmount"] .layui-table-cell').text(trunc(data.datas.breakfastAmountCount));
38                         that.elem.next().find('.layui-table-total td[data-field="chineseFoodPNum"] .layui-table-cell').text(trunc(data.datas.chineseFoodPNumCount));
39                         that.elem.next().find('.layui-table-total td[data-field="chineseFoodAmount"] .layui-table-cell').text(trunc(data.datas.chineseFoodAmountCount));
40                         that.elem.next().find('.layui-table-total td[data-field="dinnerPNum"] .layui-table-cell').text(trunc(data.datas.dinnerPNumCount));
41                         that.elem.next().find('.layui-table-total td[data-field="dinnerAmount"] .layui-table-cell').text(trunc(data.datas.dinnerAmountCount));
42                         that.elem.next().find('.layui-table-total td[data-field="takeoutPNum"] .layui-table-cell').text(trunc(data.datas.takeoutPNumCount));
43                         that.elem.next().find('.layui-table-total td[data-field="takeoutAmount"] .layui-table-cell').text(trunc(data.datas.takeoutAmountCount));
44                         that.elem.next().find('.layui-table-total td[data-field="9"] .layui-table-cell').text('总额¥'+trunc(data.datas.totalAmount));
45                     })
46                 }
47             });
48         }
49         renderTable();
1 /*去除小数点*/
2 function trunc(val){
3     return Math.floor(val);
4 }

 

 

 

标签:表格,title,true,layUI,field,layui,table,合计,data
From: https://www.cnblogs.com/itljm/p/17187581.html

相关文章