jQuery easyui中獲取datagrid某一列的值之和


我想實現的功能就是加載datagrid之和能夠計算出某一列的值之和,刪除某一行數據的時候會從總數里面減去這列這行的數據,新增一條記錄的時候也會把這個數據加在總數上面

$(function() {
$('#content').datagrid( {
toolbar : [ {
text : '新增',
iconCls : 'icon-add',
handler : function() {
...
 
}
} ],
iconCls : 'icon-save',
width : '1000',
height : 'auto',
nowrap : false,
striped : false,
url : ".....",
remoteSort : false,
loadMsg : '正在加載數據....請稍候....',
fitColumns : true,
columns : [ [ {
field : 'id',
title : '數',
align : 'left',
width : 100,
sortable : true
},{
field : 'qqq',
title : '操作',
align : 'left',
width : 100,
sortable : true,
formatter : function(obj,row) {
return method("del"," 刪除 ",row.id);
}
}] ],
onSelect : function() {
$(this).datagrid('clearSelections');
},
singleSelect : true,
pagination : true,
rownumbers : true
});
------解決方案--------------------
做成一個函數,onloadsuccess事件,添加刪除后執行一次那個函數就好了


    function compute() {
        var rows = $('xxxx').datagrid('getRows')//獲取當前的數據行
        var total = 0;
        for (var i = 0; i < rows.length; i++) {
            total += rows[i]['你的字段名稱'];
        }
        alert(total)
    }


免責聲明!

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



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