下面小編就為大家?guī)?lái)一篇jQuery easyUI datagrid 增加求和統(tǒng)計(jì)行的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。
在datagrid的onLoadSuccess事件增加代碼處理。
<style type="text/css">
.subtotal { font-weight: bold; }/*合計(jì)單元格樣式*/
</style>
<script type="text/javascript">
function onLoadSuccess() {
//添加“合計(jì)”列
$('#table').datagrid('appendRow', {
Saler: '<span class="subtotal">合計(jì)</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>
以上這篇jQuery easyUI datagrid 增加求和統(tǒng)計(jì)行的實(shí)現(xiàn)代碼就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考