本文主要是介绍jeesite列表jqGrid表格底部汇总,基于onSelectRow和onSelectAll实现选中行汇总合计,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、最终效果图
二、表格启用复选框并初始化赋值
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>
这篇关于jeesite列表jqGrid表格底部汇总,基于onSelectRow和onSelectAll实现选中行汇总合计的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!