一、最终效果图
二、表格启用复选框并初始化赋值
onSelectAll: function() { calc_sum(); },
onSelectRow: function() { calc_sum(); },
// 加载成功后执行事件
ajaxSuccess: function(data){
var dy = 0;
var glbzqmrsdtyg = 0;
var glbzqmrsschyg = 0;
var glbzqmrsqtcy = 0;
var glbzqmrsjdgz = 0;
for (let i = 0; i < data.rows.length; i++) {
var row = data.rows[i];
dy += row.dy;
glbzqmrsdtyg += row.glbzqmrsdtyg;
glbzqmrsschyg += row.glbzqmrsschyg;
glbzqmrsqtcy += row.glbzqmrsqtcy;
glbzqmrsjdgz += row.glbzqmrsjdgz;
}
$('#dataGrid').dataGrid("footerData", "set", {
'dw' : '<em>合计: </em>',
'dy' : '<em>'+dy+'</em>',
'glbzqmrsdtyg' : '<em>'+glbzqmrsdtyg+'</em>',
'glbzqmrsschyg' : '<em>'+glbzqmrsschyg+'</em>',
'glbzqmrsqtcy' : '<em>'+glbzqmrsqtcy+'</em>',
}, false);
}
三、添加合并计算方法
<script>
function calc_sum() {
var rowIds = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
console.log("打印:" +rowIds);
var sum = 0;
var dy = 0;
var glbzqmrsdtyg = 0;
var glbzqmrsschyg = 0;
var glbzqmrsqtcy = 0;
var glbzqmrsjdgz = 0;
for ( var i = 0; i < rowIds.length; i++) {
var row = $("#dataGrid").jqGrid('getRowData', rowIds[i]);
dy += Number(row.dy);
glbzqmrsdtyg += Number(row.glbzqmrsdtyg);
glbzqmrsschyg += Number(row.glbzqmrsschyg);
glbzqmrsqtcy += Number(row.glbzqmrsqtcy);
glbzqmrsjdgz += Number(row.glbzqmrsjdgz);
}
$('#dataGrid').dataGrid("footerData", "set", {
'dw' : '<em>合计: </em>',
'dy' : '<em>'+dy+'</em>',
'glbzqmrsdtyg' : '<em>'+glbzqmrsdtyg+'</em>',
'glbzqmrsschyg' : '<em>'+glbzqmrsschyg+'</em>',
'glbzqmrsqtcy' : '<em>'+glbzqmrsqtcy+'</em>',
'glbzqmrsjdgz' : '<em>'+glbzqmrsjdgz+'</em>',
}, false);
}
</script>