Bootstrap dataTables "footerCallback" sum not working
<p>Well i can make it work in JSFiddle but not in my site. Just copied the table data from my php page and removed the for each loop and replaced with some data.<br>
You can see the <a href="http://jsfiddle.net/16estcfa/" rel="nofollow">JSFiddle here</a>.  </p>

<p>Why cant I replicate the JSFiddle in my php page?<br>
  <strong>UPDATE</strong> I get in script console the following: <code>return window.wrappedJSObject || window;</code></p>

<p>My php Output is this:  </p>

<pre><code>&lt;div&gt;
&lt;table class="table table-striped table-bordered table-hover" id="myTable"&gt;
    &lt;div&gt;&lt;h2&gt;Mapa Analítica&lt;/h2&gt;&lt;/div&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th class="text-center" style="vertical-align:middle;"&gt;Name&lt;/th&gt;
            &lt;th class="text-center"&gt;Tipo Documento&lt;/th&gt;
            &lt;th class="text-center"&gt;Número&lt;/th&gt;
            &lt;th class="text-center"&gt;Cliente&lt;/th&gt;
            &lt;th class="text-center"&gt;Obra&lt;/th&gt;
            &lt;th class="text-center"&gt;Designação&lt;/th&gt;
            &lt;th class="text-center"&gt;Agregado&lt;/th&gt;
            &lt;th class="text-center sum"&gt;Quantidade (ton)&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;

    &lt;tfoot&gt;

        &lt;tr&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;
            &lt;th&gt;&lt;/th&gt;

        &lt;/tr&gt;

    &lt;/tfoot&gt;

    &lt;tbody&gt;
    &lt;?php foreach ($positions as $position): ?&gt;

            &lt;tr&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["data"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["tipo"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["num"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["cliente"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["obra"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["nome_obra"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["agr"] ?&gt;&lt;/td&gt;
                &lt;td class="text-center"&gt;&lt;?= $position["ton"] ?&gt;&lt;/td&gt;
            &lt;/tr&gt;

    &lt;?php endforeach ?&gt;
    &lt;/tbody&gt;



&lt;/table&gt;
</code></pre>

<p>  </p>

<p>The js function located in footer.php is this:  </p>

<pre><code>$(document).ready(function() {
$('#myTable').DataTable( {
    "footerCallback": function ( row, data, start, end, display ) {
        var api = this.api(), data;

        // Remove the formatting to get integer data for summation
        var intVal = function ( i ) {
            return typeof i === 'string' ?
                i.replace(/[\$,]/g, '')*1 :
                typeof i === 'number' ?
                    i : 0;
        };

        // Total over all pages
        total = api
            .column( '.sum' )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Total over this page
        pageTotal = api
            .column( '.sum', { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( '.sum' ).footer() ).html(
            '$'+pageTotal +' ( $'+ total +' total)'
        );
    }
} );
</code></pre>

<p>} );  </p>

<p>In the head element I included all the following:  </p>

<pre><code>&lt;head&gt;
    &lt;!-- jquery para colocar a cor vermelha no navbar --&gt;
    &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"&gt;&lt;/script&gt;

    &lt;!--  BOOTSTRAP --&gt;
    &lt;link href="../public/css/bootstrap.min.css" rel="stylesheet"/&gt;
    &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"&gt;
    &lt;link href="../public/css/style.css" rel="stylesheet"/&gt;
    &lt;script src="../public/js/bootstrap.min.js"&gt;&lt;/script&gt;

    &lt;!-- jquery para choosen ver: https://harvesthq.github.io/chosen/ e dataTables ver: https//www.datatables.net
            também para datetimepicker ver:https://eonasdan.github.io/bootstrap-datetimepicker/--&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.css"&gt;
    &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css"&gt;
    &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" /&gt;
    &lt;link rel="stylesheet" href="../public/js/DataTables-1.10.12/media/css/dataTables.bootstrap.min.css" /&gt;
    &lt;link rel="stylesheet" href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css" /&gt;
    &lt;link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" /&gt;



    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"&gt;&lt;/script&gt;
    &lt;script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"&gt;&lt;/script&gt;
    &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.4.2/chosen.jquery.js"&gt;&lt;/script&gt;
    &lt;script src="../public/js/DataTables-1.10.12/media/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;
    &lt;script src="../public/js/DataTables-1.10.12/media/js/dataTables.bootstrap.min.js"&gt;&lt;/script&gt;
    &lt;script src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js"&gt;&lt;/script&gt;
</code></pre>