endRender Current Row

endRender Current Row

BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0
                                       , endRender: function (rows, group)
                                                {
                                                    var tQty = rows
                                                        .data()
                                                        .pluck(3)
                                                        .reduce(function (a, b) {
                                                            return a + b.replace(/[^\d]/g, '') * 1;
                                                        }, 0) ;
                                                    var tAcc = rows
                                                        .data()
                                                        .pluck(4)
                                                        .reduce(function (a, b) {
                                                            return a + b * 1;
                                                        }, 0) ;

                                                    var tRej = rows
                                                        .data()
                                                        .pluck(5)
                                                        .reduce(function (a, b) {
                                                            return a + b * 1;
                                                        }, 0);

                                                    var tDiff = rows
                                                        .data()
                                                        .pluck(6)
                                                        .reduce(function (a, b) {
                                                            return a + b * 1;
                                                        }, 0);


                                                    var tYield = 0;
                                                    if (tAcc != 0 && tRej != 0 && tDiff != 0 )
                                                    {
                                                    tYield = tAcc / (tAcc + tRej + tDiff ) * 100;
                                                    tYield = $.fn.dataTable.render.number('', '.', 2, '').display(tYield);
                                                    }


                                                    return $('<tr/>')
                                                        .append('<td colspan="3" align="center" >' + group + '-TOTAL: ' + '</td>')
                                                        .append('<td align="right">' + tQty + '</td>')

                                                        .append('<td align="right">' + tAcc + '</td>')
                                                        .append('<td align="right">' + tRej + '</td>')
                                                        .append('<td align="right">' + tDiff + '</td>')
                                                        .append('<td align="right">' + tYield + '</td>')
                                                }
                                                , dataSrc: [1]

I want to calculate running totals or say some calculations based on grouped rows . i.e first row of the current group and last row of the current group.. how to do it?

Answers

  • BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0

    Thank you Developers...! I found the solution.
    Inside reduce() function...

  • BhavinBhattBhavinBhatt Posts: 27Questions: 9Answers: 0

    It gives wrong output... :( :( :(

  • colincolin Posts: 15,142Questions: 1Answers: 2,586

    This example sums everything in the group. You can just get the first and last rows like this:

                    var salaryAvg = rows
                        .data()
                        .pluck(5)
    
    var first = salaryAvg[0];
    var last = salaryAvg[salaryAvg.length - 1];
    

    Colin

This discussion has been closed.