rowGroup: Calculating total rows in a group not working

rowGroup: Calculating total rows in a group not working

DevMushrefDevMushref Posts: 10Questions: 4Answers: 0
edited July 2022 in Free community support

I tried the solutions and examples given by dear users in the forum:

$.extend( true, $.fn.dataTable.defaults, {
    rowGroup: {
        endRender: function ( rows, group ) {
            var avg = rows
                .data()
                .pluck('salary')
                .reduce( function (a, b) {
                    return a + b.replace(/[^\d]/g, '')*1;
                }, 0) / rows.count();

            return 'Total KPIs in '+group+': '+
                $.fn.dataTable.render.number(',', '.', 0, '$').display( avg );
        },
        dataSrc: 'publishDate',
    }
});

But it's not working, its ruing the grouping as you can see in the screenshot:

I'm trying to group the data by month & year then calculate the totals of each month.

Answers

  • DevMushrefDevMushref Posts: 10Questions: 4Answers: 0
    edited July 2022

    Lol! Right After I posted the question I solved it.

    The issue was I was plucking the wrong column.

    However, it's not calculating the rows correctly?

    first group should be total of: 5,259.

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

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.