sum columns within a group

sum columns within a group

matt_rileymatt_riley Posts: 7Questions: 1Answers: 0
edited May 2013 in DataTables 1.9
Awesome plugin! I'm soooo close to getting exactly what I want, just need a little help.

I have grouping working. Now I want to sum the columns for each group and display the total in the group header. Here's a jsfiddle of it:

http://jsfiddle.net/RgKPZ/123/

The only problem is that the columns I want to sum aren't being added together. The values are being displayed, but like a string instead of adding together like numbers. Also, not all of the values are even being displayed as a string - there are repeats going on. I tried converting using Number() and parseInt() but no luck. I'm trying to put this into the callback function (like the grouping function) so that the values will be summed after each table filter, too.

I'm sure I just have a variable wrong or in the wrong place or something, but I just can't figure it out. Frustratingly close! :-(

TIA,
Matt

Replies

  • matt_rileymatt_riley Posts: 7Questions: 1Answers: 0
    edited May 2013
    I've updated my jsfiddle to show where I'm at now. http://jsfiddle.net/RgKPZ/126/

    Basically, I've got the grouping happening first and then I'm trying to sum a specific column in each group and put the total into a div within each group.

    When looking at the fiddle, you'll see the grouped content (job 1, job 2, etc). Directly under that is a zero, which is where I'm trying to put the sum of the "minutes to sum" column.

    Uncommenting line 48 in the js is where I'm stuck. It doesn't sum correctly (returns NaN) and it replaces the whole row instead of just the div I want to put the sum in. It also seems to only do the first two groups instead of all three. So, it seems I have a selector and/or loop problem.

    I've tried messing with selectors and other jquery stuff for a while now but can't crack it. Any help greatly appreciated.
This discussion has been closed.