layui的totalRow默认为两位小数,按需要修改为整数
- 前端
- 27天前
- 69热度
- 0评论
简介: layui的totalRow默认为两位小数,按需要修改为整数
方法1:
需要修改静态资源 …\resources\static\layui\lay\modules\table.js 里面的数据。
1.定位到table.js文件的 i.eachCols 位置:

2.具体内容:
d=function(){var e=o.totalRowText || "",format=o.totalFixed !== undefined ? parseInt(o.totalFixed) : 2,i,a={};i=parseFloat(l[r]).toFixed(format);return a[r]=i,i=u(o, i, a),t ? t[o.field] || e: o.totalRow ? i || e: e}
3.说明:
添加了 totalFixed 这个自定义属性,作为toFixed(format),格式化位数。
4.使用:
table.render({
elem: '#test'
,url:'/zjjgxy/getZjjgxyCountData'
,toolbar: '#toolbarDemo' //开启头部工具栏
,defaultToolbar: ['exports']
,title: '资金监管统计'
,totalRow: true
,cols: [
[
{field:'bldw', title:'办理单位', width:100, totalRowText: '合计'}
,{field:'jgyh', title:'监管银行', width:100}
,{field:'jgsl', title:'监管数量', width:100, totalRow: true, totalFixed:'0'}
,{field:'jzmj', title:'建筑面积', width:100, totalRow: true}
,{field:'fx', title:'付息', width:100, totalRow: true}
]
]
,page: true
});
方法2:
表格渲染完成后在done函数处理:
table.render({
elem: '#demo'
,height: 312
,url: '/demo/table/data/' //数据接口
,page: true //开启分页
,totalRow: true // 开启合并行区域
,cols: [[
{field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'}
,{field: 'username', title: '用户', width:80}
,{field: 'count', title: '总次数', width:80, align:'center', totalRow: true} // 需要合并
,{field: 'pro_count', title: '问题次数', width:80, align:'center', totalRow: true} // 需要合并
]]
,done: function(res, curr, count){
var divArr = $(".layui-table-total div.layui-table-cell");
$.each(divArr,function (index,item) {
var _div = $(item);
var content = _div.html();
content = content.replace(".00","");
_div.html(content);
});
}
});