callback to sum data-sort
callback to sum data-sort

I'm trying to sum column data-sort values.
With this code
"footerCallback": function(row, data, start, end, display) {
var api = this.api();
api.columns('.sum', {
page: 'current'
}).every(function() {
var sum = this
.data()
.reduce(function(a, b) {
var x = parseFloat(a) || 0;
var y = parseFloat(b) || 0;
return x + y;
}, 0);
$(this.footer()).html(sum);
});
}
I can sum the values of the cells but in my case, the values are: 1 hour, 18 seconds, etc.
obviously the sum "19" is wrong.
I'm using data-sort="<seconds>" for each cell but I don't know how to get this value into callback.
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
Hi @sphawk ,
You can grab the nodes and do the sum based on those - something like this here.
Cheers,
Colin
like a charm!
tnx a lot colin!