no data when using footerCallback to sum a column

no data when using footerCallback to sum a column

djcamodjcamo Posts: 3Questions: 1Answers: 0

i call an external PHP file to grab data for my table using ajax and want to use the footerCallback function to sum a column, however, there doesn't seem to be any data passed to this function and i have no idea what is going on, hopefully some one call steer me in the right direction

table = jQuery('#invoiceAll').DataTable({
                "retrieve": true,
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                //"processing": true,
                //"serverSide": true,
                "ajax": {
                    url: "getInvoices.php",
                    data: {"status":"all"},
                    type: "POST",
                },
                "columns": [
                    {
                        "orderable": false,
                        "data": "0",
                        "defaultContent": "",
                    },
                    { "data": "1" },
                    { "data": "2" },
                    { "data": "3","orderable": false },
                    { "data": "4", },
                    { "data": "5",className: "centre" },
                    { "data": "6",className: "centre" },
                    { "data": "7" },
                    { 
                        "data": "8",
                        className: "right",
                        } 
                    },
                    { "data": "9",className: "right" },
                    { "data": "10","orderable": false,className:"right"}
                ],
                "order": [[5, 'asc']],
                "search": true,
                "footerCallback": function ( row, data, start, end, display ) {
                    var api = this.api(), data;
                    var intVal = function ( i ) {
                        return typeof i === 'string' ?
                            i.replace(/[\$,]/g, '')*1 :
                            typeof i === 'number' ?
                                i : 0;
                    };
                    total = api
                        .column( 8 )
                        .data()
                        .reduce( function (a, b) {
                            return intVal(a) + intVal(b);
                        }, 0 );
                    jQuery( api.column( 8 ).footer() ).html(
                        '$'+total
                    );
                }
            });

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    Hi @djcamo ,

    Everything looks fine. We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • djcamodjcamo Posts: 3Questions: 1Answers: 0

    Thanks for the comment, however, would it not be impossible to emulate a server side ajax call on the http://live.datatables.net site, because as soon as i add an ajax method i see no data - http://live.datatables.net/qelicuja/2/edit

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    This one here has an ajax call, maybe see if you can emulate it there.

    Cheers,

    Colin

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735

    You can use console.log statements in the footCallback to help debug the problem.

    Kevin

  • djcamodjcamo Posts: 3Questions: 1Answers: 0

    thanks all for your suggestions, using console log showed me where the error was, another developer added the asci character for a dollar sign in that column

This discussion has been closed.