bServerSide, fnFooterCallback and column totals.

bServerSide, fnFooterCallback and column totals.

jimmcslimjimmcslim Posts: 5Questions: 0Answers: 0
edited March 2010 in General
While fnFooterCallback is great for calculating totals from rows that are visible or contained in the DOM, if you are working with a server-side result set there doesn't seem to be a way to get a total for a column from all the rows in the server-side result set. Maybe the server-side could send back sColFooter_(int) values to indicate a total for a whole result set.

Replies

  • jimmcslimjimmcslim Posts: 5Questions: 0Answers: 0
    Ok, looks like I have this one licked...

    To _fnAjaxUpdateDraw(), after the call to _fnClearTable() I have added the following;

    [code]oSettings.oJson = json;[/code]

    In my fnFooterCallback I can then access the original JSON result;

    [code]
    function myFooterCallback(nFoot, aasData, iStart, iEnd, aiDisplay) {
    var settings = oTable.fnSettings();
    $('td:eq(3)', nFoot).html(settings.oJson.dMyInterestingTotal);
    $('td:eq(4)', nFoot).html(settings.oJson.dMyOtherInterestingTotal);
    }
    [/code]

    And of course my server-side method returns a JSON result set that includes dMyInterestingTotal and dMyOtherInterestingTotal in addition to everything else that DataTables is expecting.

    Allan, do you see any shortcomings with this approach? Can it be integrated with the official codebase?
This discussion has been closed.