Objective: Create a Total row displaying the sum of each column, such as Course1 grades, Course2 grades, and so on. I have set up a Session to handle this calculation on the client side to ensure it refreshes when the browser is refreshed.
The data structure includes entries like {Student1, Course1, Course2, Course 3, Course 4, Course 5}, {Student2, Course1, Course2, Course 3, Course 4, Course 5} and so forth.
I'm contemplating using multiple variables like {{sum_course1}} in the HTML with calculations done in Template helpers, but that seems repetitive. Is there a better approach? I've looked into server-side solutions like the aggr function, but haven't found anything ideal for the client side.
Currently, I have a working solution for calculating sums, but I am struggling to find a more efficient way to do this for all the different courses.
Template.body.helpers({
sum:function(){
var sum=0;
var cursor=Tasks.find({});
cursor.forEach(function(Tasks){
sum = Tasks.courseone + sum;
});
return sum;
}
});