Trying to sum multiple columns
Trying to sum multiple columns

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.
Answers
Use the
api
variable fromvar api = this.api();
.Not sure I totally understand but it sounds like you are describing that
table2.column(i)
is trying to access columns that aren't in the table. If so then just an if statement to set the value of11
infor (var i = index; i <= index + 11; i++)
. Change the11
to be a variable.Kevin