Sum Columns don't work
Sum Columns don't work
Sorry, but I have this problem. I read different solutions but they don't work.
I need a sum of column in my table. This is my js code but only alert with ciao doesn't show
why? Thanks
$(document).ready(function() {
$('#example').DataTable( {
footerCallback: function () {
alert("Ciao");
var api = this.api();
$( api.table().footer() ).html(
api.column( 5, {page:'current'} ).data().sum()
);
}
} );
} );
Replies
I don't think
sum()
is a function ofdata()
. Take a look at your browser's console to see if you get any errors.Does the example here help?
https://datatables.net/examples/advanced_init/footer_callback.html
Kevin
There is a sum() plug-in which would be available at any level of the chain. You do need to make sure you have included that plug-in.
It sounds like there is a Javascript error occurring. We'd need a link to a test case showing the issue to be able to say exactly what the issue is though.
Allan
Hi, I have this error in browser console
Uncaught TypeError: Cannot read property 'register' of undefinedn at Sum.js:39
this is the code in sum.js file start at row 39
jQuery.fn.dataTable.Api.register('sum()', function () {
return this.flatten().reduce(function (a, b) {
if (typeof a === 'string') {
a = a.replace(/[^\d.-]/g, '') * 1;
}
if (typeof b === 'string') {
b = b.replace(/[^\d.-]/g, '') * 1;
}
});
My project is only on localhost, where could I create a test link?
https://datatables.net/forums/discussion/12899/post-test-cases-when-asking-for-help-please-read#latest