如何对数据表中的列值求和?
var sTable = $('.datatable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
"aaSorting": [[1, "desc"]],
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": CycleTimeReport,
"aoColumns": [
{ "sName": "Course", "sClass": "ellipsis" },
{ "sName": "Cost", "sClass": "ellipsis" }
],
"fnServerData": function (sSource, aoData, fnCallback) {
var data = new Object();
data.jsonAOData = JSON.stringify(aoData);
dataToSend = data;
$.ajax({
contentType: "application/json; charset=utf-8",
type: "POST",
url: sSource,
data: JSON.stringify(dataToSend),
success: function (msg) {
fnCallback(msg);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (document.Invoice.hostname == "localhost") {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.responseText);
}
}
});
},
"fnDrawCallback": function (aoData, oObj) {
},
"oLanguage": {
"sSearch": "_INPUT_"
},
"fnInitComplete": function (oSettings, json) {
},
"bSortCellsTop": true
});
答案 0 :(得分:0)
您可以简单地使用以下代码,当您想使用时不使用dunno,可以使用回调函数或其他任何方法:
// where 3 is your column number
var total = sTable.api()
.column(3)
.data()
.reduce(function (a, b) {
return parseFloat(a) + parseFloat(b);
}, 0);