Easyui 表格底部加合计
Posted 幽默是一种心情
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Easyui 表格底部加合计相关的知识,希望对你有一定的参考价值。
$("#RetailList").datagrid({
url: "../Ajax/MemberConsumAjax.ashx",
queryParams://每次请求的参数
{
cmd: ‘documentList‘
},
showFooter: true,
fitColumns: true,
pagination: false, //允许分页
rownumbers: true, //行号
singleSelect: true,//true只能选择一行
nowrap: true,//如果为true,则在同一行中显示数据。设置为true可以提高加载性能。
striped: true, //奇偶行是否区分
collapsible: true,
columns: [[
{
field: "or_Id",
title: "操作",
align: "center",
width: "80",
formatter: function (value, row, index) {
var str = ‘<a href="javascript:void(0)" id="gre" onclick=Edit(‘ + row.or_Id + ‘) >修改</a> <a href="javascript:void(0)" id="deepRed" onclick=RedFlush(‘ + row.or_Id + ‘) >红冲</a>‘;
return str;
}
},
{
field: "or_Date",
title: "单据日期",
align: "center",
width: "100"
},
{
field: "or_Code",
title: "单据编码",
align: "center",
width: "150"
formatter: function (value, rowDate, rowIndex) {
return "<a id=‘code‘ href=‘javascript:void(0)‘ onclick=\"MemberConsume(" + rowDate.or_Id + "," + rowDate.de_Id1 + ")\">" + rowDate.or_Code + "</a>";
}
},
{
field: "price",
title: "单价",
align: "center",
width: "70"
},
{
field: "number",
title: "数量",
sum: ‘true‘,
align: "center",
width: "70"
},
{
field: "or_TotalM1",
sum: ‘true‘,
title: "金额",
align: "center",
width: "80"
},
{
field: "or_Memo",
title: "备注",
align: "center",
width: "100"
}
]],
onLoadSuccess: function (data) {
$(‘#RetailList‘).datagrid(‘statistics‘); //合计
},
});
}
$.extend($.fn.datagrid.methods, {
statistics: function (jq) {
var opt = $(jq).datagrid(‘options‘).columns;
var rows = $(jq).datagrid("getRows");
var footer = new Array();
footer[‘sum‘] = "";
for (var i = 0; i < opt[0].length; i++) {
if (opt[0][i].sum) {
footer[‘sum‘] = footer[‘sum‘] + sum(opt[0][i].field, 1) + ‘,‘;
}
}
var footerObj = new Array();
if (footer[‘sum‘] != "") {
var tmp = ‘{‘ + footer[‘sum‘].substring(0, footer[‘sum‘].length - 1) + "}";
var obj = eval(‘(‘ + tmp + ‘)‘);
if (obj[opt[0][0].field] == undefined) {
footer[‘sum‘] += ‘"‘ + opt[0][0].field + ‘":"<b>合计:</b>"‘;//第0列显示为合计
obj = eval(‘({‘ + footer[‘sum‘] + ‘})‘);
} else {
obj[opt[0][0].field] = "<b>合计:</b>" + obj[opt[0][0].field];
}
footerObj.push(obj);
}
if (footerObj.length > 0) {
$(jq).datagrid(‘reloadFooter‘, footerObj);
}
function sum(filed) {
var sumNum = 0;
var str = "";
for (var i = 0; i < rows.length; i++) {
var num = rows[i][filed];
sumNum += Number(num);
}
return ‘"‘ + filed + ‘":"‘ + sumNum.toFixed(2) + ‘"‘;
}
}
});
以上是关于Easyui 表格底部加合计的主要内容,如果未能解决你的问题,请参考以下文章