试图对数据表求和,但仅求和第一页

时间:2019-06-11 09:46:06

标签: datatables datatables-1.10

我正在尝试对数据表中的列求和。但这仅是汇总第一页吗? 两个变量RequiredoneBookedtwo仅对数据首页的值求和,而不对整个数据集:s

求和
    var sTable = $('.datatable').dataTable({
    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "bScrollCollapse": true,
    "aaSorting": [[1, "desc"]],
    "bServerSide": true,
    "bProcessing": true,
    "sAjaxSource": CycleTimeReport,
    "aoColumns": [
        { "sName": "one", "sClass": "ellipsis" },
        { "sName": "two", "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);
                }
            }
        });
    },
    "fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) {

            var Requiredone = 0;
            var Bookedtwo = 0;

            for (var i = 0; i < aaData.length; i++) {
                Requiredone+= aaData[i][2] * 1;
                Bookedtwo += aaData[i][3] * 1;
            }
},
    "oLanguage": {
        "sSearch": "_INPUT_"
    },
    "fnInitComplete": function (oSettings, json) {
    },
    "bSortCellsTop": true
});

1 个答案:

答案 0 :(得分:0)

您正在使用服务器端的数据处理。因此,您的datatable-object仅具有当前显示页面的数据。您必须在服务器端实现总和,并将其添加到JSON响应中,或者在额外的ajax请求中执行。

另一种选择是禁用服务器端处理并预填充表元素,或者使用包含所有数据的json对象填充datatales-settings的aaData属性。