jQuery easyUI datagrid 增加求和統計行


在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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM