function compute() {
var rows = $("#rep").datagrid("getRows")//
获取当前的数据行
//
计算总和
var rtotal = 0, hctotal = 0
, wftotal = 0, zgwctotal = 0, mzgtotal = 0, is_heji = 0;
for (
var i = 0; i < rows.length; i++) {
rtotal += parseFloat(rows[i]['completeTask']);
hctotal += parseFloat(rows[i]['totalTask']);
wftotal += parseFloat(rows[i]['zongfindProblem']);
zgwctotal += parseFloat(rows[i]['completeRectification']);
mzgtotal += parseFloat(rows[i]['noCompleteRectification']);
//率:对存在NaN的值转换(根据实际情况选择)
var a = (rtotal / hctotal * 100).toFixed(2);
var b = (wftotal / hctotal * 100).toFixed(2);
var c = (zgwctotal / wftotal * 100).toFixed(2);
if (a == "NaN") {
a = 0.00;
}
if (b == "NaN") {
b = 0.00;
}
if (c == "NaN") {
c = 0.00;
}
//排序或者在查询下一页的数据也会启动到compute()函数,所以当产生了合计值行的时候就不在重新添加一行合计,只是对数据进行重新的计算
if (rows[i]['areaname'] == "<b>
合计:</b>") {
is_heji = 1;
}}
if (is_heji == 0) {
//
新增一行显示统计信息
$("#rep").datagrid('appendRow', {
areaname: '<b>
合计:</b>',
completeTask: rtotal, totalTask: hctotal, findProblemRate: b,
completeRectificationRate: c, zongfindProblem: wftotal, completeRectification: zgwctotal,
noCompleteRectification: mzgtotal, completeTaskRate: a
});
}
}
$("#rep").datagrid({
onLoadSuccess: compute,//页面刷新的时候触发求和的函数
singleSelect:
true, //
选中一行的设置
AllowPaging:
true,
pagination:
true,
pageSize: 20,
pageList: [20, 50, 200, 1000],
rownumbers:
true, //
行号
iconCls: "icon-save", //
图标
collapsible:
true, //
隐藏按钮
border:
true,
fit:
true,
remoteSort:
false
}