在datagrid的onloadsuccess事件增加代碼處理。
<style type="text/css">
.subtotal { font-weight: bold; }/*合計單元格樣式*/
</style>
<script type="text/javascript">
function onloadsuccess() {
//添加“合計”列
$('#table').datagrid('appendrow', {
saler: '<span class="subtotal">合計</span>',
totalordercount: '<span class="subtotal">' + compute("totalordercount") + '</span>',
totalordermoney: '<span class="subtotal">' + compute("totalordermoney") + '</span>',
totalorderscore: '<span class="subtotal">' + compute("totalorderscore") + '</span>',
totaltrailcount: '<span class="subtotal">' + compute("totaltrailcount") + '</span>',
rate: '<span class="subtotal">' + ((compute("totalorderscore") / compute("totaltrailcount")) * 100).tofixed(2) + '</span>'
});
}
//指定列求和
function compute(colname) {
var rows = $('#table').datagrid('getrows');
var total = 0;
for (var i = 0; i < rows.length; i++) {
total += parsefloat(rows[i][colname]);
}
return total;
</script>