Rowgroup sum

Rowgroup sum

Jordano95Jordano95 Posts: 3Questions: 2Answers: 0

I wanted to use rowgroup plugin to get subtotal of each subgroup http://jsfiddle.net/X5LB9/ i tried thi fiddle but i can't use it in my case , the colouns of the total say "undefined" this is my code please spmeone can help me?

```
var table = $('#elencoRiepilogo').not('.initialized').addClass('initialized').show().DataTable({
"stateSave": false,

"displayLength": 100,

    "language": {
        "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json",
        "decimal": ",",
        "thousands": "."
    },

    "ajax": {
        "url": modulo+"_get_elenco.php", //?tipo=json
        "dataSrc": ""

    },

     "columns": dati,
    "order":[2,'desc'],
    "columnDefs": [

        {  

            "targets":[0,1,3,4,5,6,7],
            "searchable": false, // disabilita la ricereca per il campo con indice 0
            "orderable": false, // disabilita l'ordinamento4
            "visible":false
        }, 


    ],

"drawCallback": function ( settings ) {
var api = this.api();
var rows = api.rows({ page: 'current' }).nodes();
var last = null;
var cols = 4;
var totale = new Array();
totale['Totale'] = new Array();
var groupid = -1;
var subtotale = new Array();
api.column(2, { page: 'current' }).data().each(function(group, i) {
console.log('group', group);
console.log('index', i);
//var groupEnd=i;
if (last !== group) {
groupid++;
console.log('GroupID after', groupid);
$(rows).eq(i).before(
'<tr class="group"><td> Total ' + group + '</td></tr>'
);
last = group;}

var val = api.row(api.row($(rows).eq(i)).index()).data(); //current order index
$.each(val, function(index2, val2) {
if (typeof subtotale[groupid] == 'undefined') {
subtotale[groupid] = new Array();
}
if (typeof subtotale[groupid][index2] == 'undefined') {
subtotale[groupid][index2] = 0;
}

            var valore = Number(val2);
            console.log('valore', valore);
            //subtotale[groupid][index2] += valore;
            subtotale[groupid][index2] = +parseFloat(subtotale[groupid][index2] + valore).toFixed(2);
            console.log('sub total', subtotale[groupid][index2]);

        });
    });
    $('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 = 2; a < cols; a++) {
            subtd += '<td align="right">' + $.fn.dataTable.render.number(',', '.', 2, '$').display(subtotale[i][a]) + '</td>';
        }
        $(this).append(subtd);
    });

    },
    dom:'tp'} );

$('.table-responsive tbody').on( 'click', 'tr.group', function () {
    var rowsCollapse = $(this).nextUntil('.group');
    $(rowsCollapse).toggleClass('hidden');
}); ```

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    Can you build a running example with your code so we can help debug?

    Kevin

This discussion has been closed.