layui table 合并计算
关键
开启:totalRow: true,
显示:
{field: 'tempId', width: 80, align: 'center', title: 'ID', sort: true, totalRowText: '合计'},
{field: 'callOut', width: 100, align: 'center', title: '呼出次数', totalRow: true, sort: true},
完整
table.render({
elem: '#' + tableId,
id: tableId,
url: url,
method: 'POST',
toolbar: '#' + tableId + '-toolbar',
title: '话务量',
defaultToolbar: ['filter', 'exports'],
headers: {token: layui.config.getToken()},
page: 0,
limits: [],
totalRow: true,
request: admin.getTablePageParam(),
initSort: {field:'callSecondTotal', type:'desc'},
where: {
...params
},
cols: [
[
{field: 'tempId', width: 80, align: 'center', title: 'ID', sort: true, totalRowText: '合计'},
{field: 'seatNum', width: 80, align: 'center', title: '坐席号'},
{field: 'name', width: 100, align: 'center', title: '咨询师'},
{field: 'deptName', hide: true, width: 120, align: 'center', title: '所属部门'},
{field: 'callOut', width: 100, align: 'center', title: '呼出次数', totalRow: true, sort: true},
{field: 'callOutOk', width: 100, align: 'center', title: '通话次数', totalRow: true, sort: true},
{field: 'callOutRate', width: 100, align: 'center', title: '通话率', sort: true, templet: '#seat-record-statistics-user-list-callOutRate-tpl'},
{field: 'callOutLoss', hide: true, width: 100, align: 'center', title: '呼损数', totalRow: true, sort: true, templet: '#seat-record-statistics-user-list-callOutLoss-tpl'},
{field: 'callSecondTotal', minWidth: 100, align: 'center', title: '通话时长', totalRow: true, sort: true, templet: '#seat-record-statistics-user-list-callSecondTotal-tpl'},
{field: 'callSecondAvg', minWidth: 100, align: 'center', title: '通话均长', sort: true, templet: '#seat-record-statistics-user-list-callSecondAvg-tpl'},
{field: 'callSecondMax', minWidth: 100, align: 'center', title: '最长通话时长', sort: true, templet: '#seat-record-statistics-user-list-callSecondMax-tpl'},
]
],
done:function(res, curr, count){//用于合计数据取整数
var divArr = $(".panel-seat-record-statistics-user .layui-table-total div.layui-table-cell");
$.each(divArr,function (index,item) {
if (index === 6) {
$(item).html('<span class="c-success">'+ parseInt($(item).html() || 0) / 100 +'%</span>')
}
else if (index === 8) {
$(item).html('<span class="">'+ layui.tool.formatSeconds(parseInt($(item).html())) +'</span>')
}
else if (index === 9) {
$(item).html('<span class="c-primary">'+ layui.tool.formatSeconds(parseInt($(item).html())) +'</span>')
}
});
}
});
效果图