Hi, I wand to group on the first column and total the last three columns. I used the example provided however the totals appear at the end of the page instead of after the group and are "NaN". Also, is it possible to only provide a total at the end of a group and not when a group finishes at the end of a page (i.e., if a group goes over three pages have one total at the end)?
The code is (I tried with rowGroup first):
var activityUpdateTable = $('#activityUpdateTable').DataTable( {
"info": false,
dom: 'Bfrtip',
buttons: ['copy', 'csv', 'excel', 'pdf', 'print'],
columns: [
{ data: null, render: function ( data, type, row ) {
// Combine the first and last names into a single table field
return data.surname+', '+data.firstname;
} },
{data: 'startDate',
defaultContent: ""},
{data: 'type',
defaultContent: ""},
{data: 'description',
defaultContent: ""},
{data: 'kilometres',
defaultContent: "0"},
{data: 'nightsUnderCanvas',
defaultContent: "0",
},
{data: 'nightsInBuilding',
defaultContent: "0",
},
],
columnDefs: [ {
targets: [1],
render: $.fn.dataTable.render.moment( 'DD/MM/YYYY' )
} ],
rowGroup: {
startRender: null,
endRender: function ( rows, group ) {
var kmTotal = rows
.data()
.pluck(4)
.reduce( function (a, b) {
return a + b*1;
}, 0);
var canvasTotal = rows
.data()
.pluck(5)
.reduce( function (a, b) {
return a + b*1;
}, 0);
var buildingTotal = rows
.data()
.pluck(6)
.reduce( function (a, b) {
return a + b*1;
}, 0);
return $('<tr/>')
.append( '<td colspan="4">Totals:</td>' )
.append( '<td>'+kmTotal+'</td>' )
.append( '<td>'+canvasTotal+'</td>' )
.append( '<td>'+buildingTotal+'</td>' );
},
dataSrc: 0
},
} );