Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82803

Summing column with subtotals

$
0
0

I am trying to sum a column of numbers that have subtotals without including the subtotals in the total. I have added the class of "skipit" to the subtotals and am looking for an approach that will selectively add the column excluding those having the skipit class. Near all the examples I can find are using the .reduce method and that would seem to eliminate the possibility of class making any difference.

So I have pieced together the following from various posts but it seems I am still some distance from arriving at a workable solution.

Summing column 4:

var intVal = function (i) {
    return typeof i === 'string' ?
            i.replace(/[\$,]/g, '') * 1 :
            typeof i === 'number' ?
            i : 0;
};

var api = this.api(),
        totala = 0;
api.rows(":not('.skipit')").every(function () {
totala +=intVal(this.data()[4]);
});

$(api.column(4).header()).html(totala);

Any help would be appreciated.

Thanks,
Jim


Viewing all articles
Browse latest Browse all 82803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>