HopesAreMiracle
1 year ago

How can i sum Total value of current page using Footercallback.

Posted 1 year ago by HopesAreMiracle

Hello All , I have a problem with my footercallback funtion. I cannot sum the total value of current page. I also use the page:'current' . But the actual total amount is total amount from all over the page. When i change page 1 to 2 the total amount still the same . Should be change right? How can i do it for that error. My code is below.

$(document).ready(function() {

$('#tbl-treport').dataTable({
    
  
    "footerCallback": function ( row, data, start, end, display ) {
        var api = this.api();

        // converting to interger to find total
        var intVal = function ( i ) {
            return typeof i === 'string' ?
                i.replace(/[$,]/g, '')*1 :
                typeof i === 'number' ?
                    i : 0;
        };

        // computing column Total of the complete result 
       
            
        var from_amount_in_sgd = api
        .column( 8, { page: 'current'} )
        .data()
        .reduce( function (a, b) {
            return intVal(a) + intVal(b);
        } );

var numFormat = $.fn.dataTable.render.number( ',', '.', 3).display;

        $( api.column( 6 ).footer() ).html("Total Amount");
      
        $( api.column( 8 ).footer() ).html(numFormat(from_amount_in_sgd));

},

} );

});

Please sign in or create an account to participate in this conversation.