Quantcast
Channel: DataTables 1.10 — DataTables forums
Viewing all articles
Browse latest Browse all 2364

Calculate the Total of Every Other Row in a Row Group

$
0
0

Link to test case (Using a simplified data set): http://live.datatables.net/zuzaxute/1/edit
Debugger code (debug.datatables.net): https://debug.datatables.net/idudix
Error messages shown: jquery.min.js:2 jQuery.Deferred exception: rows is not a function TypeError: rows is not a function
Description of problem: Within my rowGrouping, I have an editable row and then a non-editable reference row right below it and a group sum at the end. I only want to sum the editable rows, which have a tr class of ".override" (they also happen to be the odd rows if that's easier to test). However, I keep getting the error message row/rows is not a function. Selecting the correct rows outside of the rowGrouping works perfectly, but I can't get it to work inside of the rowGrouping. Here's the code I'm using, everything works except when I try and apply the filter section. My goal is just to ignore the reference rows in the group sum.

            var table = $('#myTable').dataTable({
                rowGroup: {
                    startRender: null,
                    endRender: function (rows, group) {

                        //Need to calculate the total of every other row;
                        var catSum = rows
                            .filter(function (rowIdx) {
                                return $(rows(rowIdx).node()).hasClass('.override') ? true:false;
                            })
                            .data()
                            .pluck(15)
                            .reduce(function (a, b) {
                                return a + b.replace(/[^\d]/g, '') * 1;
                            }, 0);
                        catSum = $.fn.dataTable.render.number(',', '.', 0, '$').display(catSum);

                        return $('<tr/>')
                            .append('<td colspan="15">Sum of ' + group + '</td>')
                            .append('<td>' + catSum + '</td>');
                    },
                    dataSrc: 0
                },
                lengthMenu: [[100, 250, 500, -1], [100, 250, 500, "All"]],
                ordering: false,
                scrollY: '50vh',
                scrollCollapse: true,
            });
        });

Viewing all articles
Browse latest Browse all 2364

Trending Articles