All, i am using RowGrouping on Data table,For each Group i need to do Subtotal on some of columns(Encum,Paid,Balance) and Total on All the row for Column(Encum,Paid,Balance). i am quite new to this Datatable and not able to achieve the result what i needed. Here is the code is have used. i need to display $value of 3 of those column and also do subtotal at the header. Please help me out here, code in jsfiddle: jsfiddle.net/6r2pjbg8
var table = S$('#EncumbranceSummaryTable').DataTable({
"columnDefs": [
{ "visible": false, "targets":0 }
],
"stateSave": false,
"stateDuration": 60*60*24*365,
"data" : POnbrsDetails,
"columns":[
{"sTitle": "PO #", "data": "PO_Nbr" },
{"sTitle": "FY", "data": "FY" },
{"sTitle": "LN", "data": "LN" },
{"sTitle": "F/O/A","data":"FOA"},
{"sTitle": "Project ID", "data": "Proj_ID" },
{"sTitle": "Srce Type", "data": "Srce_Type" },
{"sTitle": "Encumbrance","data":"Encum_Amt"},
{"sTitle": "Paid","data":"Paid"},
{"sTitle": "Balance", "data": "Balance" }
],
"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows( {page:'current'} ).nodes();
var last=null;
var colonne = api.row(0).data().length;
var totale = new Array();
totale['Totale']= new Array();
var groupid = -1;
var subtotale = new Array();
api.column(0, {page:'current'} ).data().each( function ( group, i ) {
debugger;
if ( last !== group ) {
S$(rows).eq( i ).before(
'<tr class="group"><td colspan="5">'+group+'</td></tr>'
);
last = group;
}
//sub total
val = api.row(api.row($(rows).eq( i )).index()).data(); //current order index
$.each(val,function(index2,val2){
debugger;
if (typeof subtotale[groupid] =='undefined'){
subtotale[groupid] = new Array();
}
if (typeof subtotale[groupid][index2] =='undefined'){
subtotale[groupid][index2] = 0;
}
if (typeof totale['Totale'][index2] =='undefined'){
totale['Totale'][index2] = 0;
}
// valore = Number(val2.replace('€',"").replace('.',"").replace(',',"."));
subtotale[groupid][index2] += 1;
totale['Totale'][index2] += 2;
});
} );
$('tbody').find('.group').each(function (i,v) {
var rowCount = $(this).nextUntil('.group').length;
//$(this).find('td:first').append($('<span />', { 'class': 'rowCount-grid' }).append($('<b />', { 'text': ' ('+rowCount+')' })));
var subtd = '';
for (var a=0;a<3;a++)
{
subtd += '<td>'+ subtotale[i][a] +'</td>';
}
$(this).append(subtd);
});
}
});
Does this work for you?
Working JSFiddle.