Datatable sum column by row grouping and show sum result at the end of each group

Datatable sum column by row grouping and show sum result at the end of each group

cse111cse111 Posts: 2Questions: 1Answers: 0

I am using datatable row grouping from https://datatables.net/examples/advanced_init/row_grouping.html and it works fine.

I have scenario as shown in image:

Now I want to calculate sum(sub-total) by each grouping abd show result in row at the end of grouping as you see in image.

At the end of listing , want to show a final row of total amount. How to accomplish that.
Js code used is

$(function() {
    var table = $('#table').DataTable({
    "columnDefs": [
        { "visible": false, "targets": 1 }
    ],
    "order": [[ 1, 'asc' ]],
    "displayLength": 25,
    "drawCallback": function ( settings ) {
        var api = this.api();
        var rows = api.rows( {page:'current'} ).nodes();
        var last=null;

        api.column(1, {page:'current'} ).data().each( function ( group, i ) {
            if ( last !== group ) {
                $(rows).eq( i ).before(
                    '<tr class="group" style="background-color:#F5F5F5;"><td colspan="3">'+group+'</td></tr>'
                );

                last = group;
            }
        } );
    }
    });
});

Answers

This discussion has been closed.