Add row to show "grand total" after "tfoot"

Add row to show "grand total" after "tfoot"

Lontar8Lontar8 Posts: 7Questions: 3Answers: 0
edited April 2020 in Free community support

at tfoot, has the select option

$('#tableOrder' tfoot tr th').each( function (i){
    var select = $('<select><option value=""></option></select>').appendTo($(this).empty()).on('change', function() {
        var val = $(this).val();
        table.column(i).search(val ? '^' + $(this).val() + '$' : val, true, false).draw();
    });
        table.column(i).data().unique().sort().each(function(d, j) {
        select.append('<option value="' + d + '">' + d + '</option>')
    }); 
});

i would like to add this rowGroup, one row below the tfoot section, how to set it up ???

rowGroup: {      
    startRender: null,
    endRender: function (rows, group) {
            var sum = rows
            .data()
            .pluck('total') //.pluck(7) result NaN
            .reduce( function (a, b) {
                 return a + b*1;
             }, 0);
    
    return $('<tr/>')
    .append('<td> ' + group + '</td>')
    .append('<td>' +' (' +rows.count() +' rows)')
    .append('<td/>' )
    .append('<td/>' )
    .append('<td/>' )
    .append('<td>' +'Total Order by Group '+$.fn.dataTable.render.number(',', '.', 0, '$').display( sum )+'</td>')
    .append('<td/>' )
    },
    dataSrc: 'seller' 
},

thank you

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    RowGroup groups records within the table, not below the footer, see example here.

    Colin

  • Lontar8Lontar8 Posts: 7Questions: 3Answers: 0

    Noted rowGroup must be inside Table, thank you for the advice.

    but i still cannot figure it out how to make rowGroup to add another line for GrandTotal (the second line of "endRender"

    the previous rowGroup code is work fine..
    that every "Group" of seller, will have subtotal of each group at column 7.

    after the last group, with its corresponding subtotal
    need to have GrandTotal for all the records.... and need to be located right between the last group subtotal and before the tfoot line

    thank you

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954
    edited April 2020 Answer ✓

    I think it would be easier to have two footer rows with the first for the totals you want and the second with the search inputs.

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Could you add another line in the tfoot and use that for your rendering?

    Colin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    great minds... ;)

This discussion has been closed.