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

Trying to sum multiple columns

$
0
0

Hello.

I've a column for each week of the year containing different numbers. So when each column renders I do a sum for that column in the footer. But I also would like to do a sum for that column and 3 months ahead (this + 11 columns ahead) for each column.

   footerCallback: function () {
            var api = this.api();
            api.columns('.sum', {
                page: 'current'
            }).every(function (index) {
                var sum = this.data().sum();

                // How should I do this instead of referencing the table again? Or is this OK?
                // I cannot reach the table variable created when creating the DataTable in document ready.
                var table2 = $('#assignmentReport').DataTable();
                for (var i = index; i <= index + 11; i++) {
                        var s = table2.column(i).data().sum();
                        console.log(s)
                }
            });
        }

The problem with this solution is that it continues for 11 weeks the last week 52 also, so it throws an error:

Cannot read property 'sDefaultContent' of undefined

Could someone guide me in the right direction?

Thanks in advance.


Viewing all articles
Browse latest Browse all 81970

Trending Articles



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