I have a DataTables done as follows:
month_col = [13,14,15,16,17,18,19,20,21,22,23,24];
$('#revenueTable').DataTable({
scrollX: true,
stateSave: true,
order: [[0, 'asc']],
lengthMenu: [
[ 10, 25, 50, -1 ],
[ '10 rows', '25 rows', '50 rows', 'Show all' ]
],
dom: 'Bfrtip',
columnDefs: [
{
"targets": [ 2,9 ],
"visible": false,
"searchable": false
}
],
buttons: [
{
extend: "colvis",
className: "btn-sm",
columns: [0,1,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]
},
{
extend: "pageLength",
className: "btn-sm"
},
{
extend: "csv",
className: "btn-sm",
exportOptions: {
columns: ':visible'
}
},
{
extend: "excel",
className: "btn-sm",
exportOptions: {
columns: ':visible'
}
},
{
extend: "print",
className: "btn-sm",
exportOptions: {
columns: ':visible'
}
},
],
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;
};
$.each(month_col, function( index, value ) {
// Total over all pages
total = api
.column( value )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Total over this page
pageTotal = api
.column( value, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( api.column( value ).footer() ).html(
'<div style="font-size: 150%;">'+pageTotal+'</div>'
);
});
}
});
And you can find below a picture of the table with some sample data:
At the moment, the footer callback is summing the columns. The problem is I need to make the sum in a certain condition: If the column "project status" is started then I add the value but if the column "project status" is pipeline then I need to add the value multiplied by the win ratio.
Is it possible?