从数据表中检索最后一个值

时间:2019-06-10 14:32:17

标签: jquery datatables

如何从fnDrawCallback函数内表的最后一行检索值?

我正在尝试在页面上做其他事情,但只需要已发送回的数据中特定列中的一个值

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
    });

1 个答案:

答案 0 :(得分:0)

"fnFooterCallback": function (nRow, aaData, iStart, iEnd, aiDisplay) {

            var RequiredExpenditure = 0;
            var BookedExpenditure = 0;
            var CompletedExpenditure = 0;
            var ExpingExpenditure = 0;

            for (var i = 0; i < aaData.length; i++) {
                RequiredExpenditure += aaData[i][2] * 1;
                BookedExpenditure += aaData[i][3] * 1;
                CompletedExpenditure += aaData[i][4] * 1;
                ExpingExpenditure += aaData[i][5] * 1;
            }

}