前端自动计算
表格代码:
layui.use('table', function(){ var table = layui.table; //第一个实例 table.render({ elem: '#demo' ,height: 312 ,url: '../../demo/table/user/-page=1&limit=30.js' //数据接口 ,page: true //开启分页 ,totalRow:true ,cols: [[ //表头 {field: 'id', title: 'id', align: 'center', fixed: "left"}, {field: 'name', title: '名称', align: 'center', totalRowText: '合计'}, {field: 'money', width: 120, title: '金额', align: 'center',totalRow:true} ]] }); });
这里注意
totalRowText 表示这列的最后一行的文字
totalRow:true 表示自动计算这列的总和
后端返回绑定
接口返回合计数据
{ "code": 0, "totalRow": { "score": "666" }, "data": [{}, {}], "msg": "", "count": 1000 }
前端绑定
layui.use('table', function(){ var table = layui.table; //第一个实例 table.render({ elem: '#demo' ,height: 312 ,url: '../../demo/table/user/-page=1&limit=30.js' //数据接口 ,page: true //开启分页 ,totalRow:true ,cols: [[ //表头 {field: 'id', title: 'id', align: 'center', fixed: "left"}, {field: 'name', title: '名称', align: 'center', totalRowText: '合计'}, {field: 'money', width: 120, title: '金额', align: 'center',totalRow:"score"} ]] }); });