How can I re-format the footerCallback
How can I re-format the footerCallback
DataTalk
Posts: 1Questions: 1Answers: 0
// COLUMN CALCULATUON FUNCTION
"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; };
// ENTER COLUMN NUMBER
// Total over all pages
total = api .column( 10 ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 );
// Total over this page
pageTotal = api .column( 10, { page: 'current'} ) .data() .reduce( function (a, b) { return intVal(a) + intVal(b); }, 0 );
// Update footer
$( api .column( 10 ).footer() ).html( '$'+ total +'' );
// END
},
THE ABOVE RETURNS $1385.6399999999999
How can I re-format the intVal so it returns $1385.64
This discussion has been closed.
Answers
You can use the Javascript toFixed() method.
Kevin