how to add or subtract from a column depending on another column colour text in FooterCallback
how to add or subtract from a column depending on another column colour text in FooterCallback

Hello, I have this situation where I want to have the footer of column 4 SUM the values when the Column 3 is red texted but to subtract when the Column 3 is blue texted.
footerCallback: function (row, data, start, end, display) {
var api = this.api();
// 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;
};
//Σύνολο Τιμών
var totalA = 0;
api.cells(null, 3, {
page: 'current'
})
.nodes()
.each(function(n) {
if($(n)
.hasClass('text-danger')) {
//totalA += intVal(api.row(counter).data()['amount']);
//totalA += intVal($(n)
//.text());
}
})
$(api.column(4).footer()).html('€' + totalA);
thank you very much
Answers
I would try using
cells().every()
and in the function you can get thecell().data()
(as shown in the docs example) and thecell().node()
. If you still need help then please build a simple test case with an example of your data and yourfooterCallback
.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin