title: Sum Footer on DataTable
body: <p>I'm trying to put sum of mysql data in my datatable footer but it displays nothing, I haven't received any error in my code just showing nothing. By the way, the output is based on date range.</p>
  
  <pre><code>    &lt;table id="product_data" class="table table-bordered table-striped"&gt;
       &lt;thead&gt;
        &lt;tr&gt;
         &lt;th&gt;Date&lt;/th&gt;
         &lt;th&gt;Invoice Number&lt;/th&gt;
         &lt;th&gt;Code&lt;/th&gt;
         &lt;th&gt;Model&lt;/th&gt;
         &lt;th&gt;Desc&lt;/th&gt;
         &lt;th&gt;Price&lt;/th&gt;
         &lt;th&gt;Qty&lt;/th&gt;
         &lt;th&gt;Total&lt;/th&gt;
        &lt;/tr&gt;
       &lt;/thead&gt;
        &lt;tfoot&gt;
          &lt;tr&gt;
              &lt;th colspan="4" style="text-align:right"&gt;Total:&lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/tfoot&gt;
  </code></pre>
  
  <p></p>
  
  <p>This is my code for javascript, this is totally working but display nothing in the footer. I have to get the sum of TOTAL column which is in 7th order.</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript" &gt; 
  $(document).ready(function(){
   function fetch_data(is_date_search, from_date='', to_date='')
   {
    var dataTable = $('#product_data').DataTable({
  
     "processing" : true,
     "serverSide" : true,
     "order" : [],
     "ajax" : {
      url:"fetch_dsr.php",
      type:"POST",
      data:{
       is_date_search:is_date_search, from_date:from_date, to_date:to_date
      }
     },
  
       "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;
              };
  
              var amtTotal = api
                  .column( 7 )
                  .data()
                  .reduce( function (a, b) {
                      return intVal(a) + intVal(b);
                  }, 0 );
  
  
  
             $( api.column( 7 ).footer() ).html('amtTotal');
          },
  
  
         dom: 'Bfrtip',
          buttons: [{
          extend: 'pdf',
          download: 'open',
      customize: function(doc) {
  
         console.dir(doc)
         doc.content[1].margin = [ 0, 0, 0, 0 ] //left, top, right, bottom
      }
  
          }]
  
    });
   }
  
   $('#search').click(function(){
    var from_date = $('#from_date').val();
    var to_date = $('#to_date').val();
    if(from_date != '' &amp;&amp; to_date !='')
    {
     $('#product_data').DataTable().destroy();
     fetch_data('yes', from_date, to_date);
    }
    else
    {
     alert("Date is required");
    }
     }); 
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>//PHP fetch_dsr , fetch data</p>
  
  <pre><code>&lt;?php
  
  $connect = mysqli_connect("localhost", "root", "", "mydb");
  $column = array("soldout_tb.s_ID", "soldout_tb.invoice_date", "soldout_tb.invoice_number","soldout_tb.order_number", "soldout_tb.control_number","soldout_tb.remarks");
  $query = "
   SELECT * FROM soldout_tb 
   INNER JOIN allinvty3 
   ON allinvty3.in_code = soldout_tb.itemcode 
  ";
  $query .= " WHERE ";
  
  
  if($_POST["is_date_search"] == "yes")
  {
   $query .= 'soldout_tb.invoice_date BETWEEN "'.$_POST["from_date"].'" AND "'.$_POST["to_date"].'" AND ';
  }
  
  
  if(isset($_POST["search"]["value"]))
  {
   $query .= '(soldout_tb.s_ID LIKE "%'.$_POST["search"]["value"].'%" ';
   $query .= 'OR soldout_tb.invoice_date LIKE "%'.$_POST["search"]["value"].'%" ';
   $query .= 'OR soldout_tb.invoice_number LIKE "%'.$_POST["search"]["value"].'%" ';
   $query .= 'OR soldout_tb.control_number LIKE "%'.$_POST["search"]["value"].'%" ';
   $query .= 'OR soldout_tb.order_number LIKE "%'.$_POST["search"]["value"].'%") ';
  }
  
  if(isset($_POST["order"]))
  {
   $query .= ' ORDER BY '.$column[$_POST['order']['0']['column']].' '.$_POST['order']['0']['dir'].' ';
  }
  else
  {
   $query .= '  ORDER BY soldout_tb.control_number ASC ';
  }
  
  $query1 = '';
  
  
  $number_filter_row = mysqli_num_rows(mysqli_query($connect, $query));
  
  $result = mysqli_query($connect, $query . $query1);
  
  $data = array();
  
  while($row = mysqli_fetch_array($result))
  {
   $sub_array = array();
    $sub_array[] = $row["invoice_date"];
     $sub_array[] = $row["invoice_number"];
   $sub_array[] = $row["itemcode"];
   $sub_array[] = $row["ecr_desc"];
    $sub_array[] = $row["ite_desc"];
   $sub_array[] = $row["price"];
    $sub_array[] = $row["qty"];
    $sub_array[] = $row["total_amount"];
  
   $data[] = $sub_array;
  }
  
  function get_all_data($connect)
  {
   $query = "SELECT * FROM soldout_tb ";
   $result = mysqli_query($connect, $query);
   return mysqli_num_rows($result);
  }
  
  $output = array(
   "draw"    =&gt; intval($_POST["draw"]),
   "recordsTotal"  =&gt;  get_all_data($connect),
   "recordsFiltered" =&gt; $number_filter_row,
   "data"    =&gt; $data
  );
  
  echo json_encode($output);
  
  ?&gt;
  </code></pre>