Footer Callback Total of Column By Distinct Columns
Footer Callback Total of Column By Distinct Columns
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi
I am using the Footer Callback as described in the blog post
https://datatables.net/examples/advanced_init/footer_callback.html
I have replicated the above test case for my requirements
https://jsfiddle.net/cpshart/s478gvcj/47/
The above report shows the dividend payments made by each stock and the value of each stock in a given portfolio ( Hypothetical Figures ).
``` In this example the stock holdings across portfolios are as follows
Portfolio Symbol Value
DEA GSK 26000
ISA RLSEB 30000
ISA GSK 44000
DEA RLSEB 20000
So in the example the total value would be the sum of the Value figures above ``` 120000 ```
On 2020-11-30 RLSEB payment due £30 dividend
On 2021-02-30 RLSEB payment due £50 dividend
etc.
```
I need to write the total of the Value field using Footer Callback for each unique key value of <Portfolio><Symbol>
Any help much appreciated.
Many Thanks
Colin
This question has accepted answers - jump to:
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Hi colin
Thanks for your reply, I have created a test case already, shown above although not as a link, here is the link below
https://jsfiddle.net/cpshart/s478gvcj/47/
Thanks Colin
Thanks for that, but can you say what you would expect to happen in that test case, and what's happening instead. I'm not following your description in the OP,
Colin
Hi colin
I have raised a call on https://stackoverflow.com below with another explanation of the problem, hopefully more understandable.
https://stackoverflow.com/questions/64976444/javascript-footer-callback-sum-values-in-one-column-for-each-unique-combined-val
Thanks Colin
I would look at creating an object variable to contain the sums of each group. Use
rows().every()
to loop all the rows. In the loop build a key that is the<Portfolio><Symbol>
combined and add the value to that key. Pseudo code:mySum[<Portfolio><Symbol>] += value
.See the updated example:
https://jsfiddle.net/fL3t6bec/
Kevin
Hi Kevin
Thanks for your response, I will use some of the code from your jsfiddle, I also have a working response from the question I put on https://stackoverflow.com/ below
https://stackoverflow.com/questions/64976444/javascript-footer-callback-sum-values-in-one-column-for-each-unique-combined-val
Best regards
Colin
I misunderstood your requirement. I though you want the sum of each
<Portfolio><Symbol>
, grouped by<Portfolio><Symbol>
. Looks like you only need the total sum of one value for each<Portfolio><Symbol>
.Kevin
Hi Kevin
No problems, you are 100% correct above, mine was an unusual requirement, so I can appreciate the misunderstanding.
I have it working now using the workings of the https://stackoverflow.com/questions/64976444/javascript-footer-callback-sum-values-in-one-column-for-each-unique-combined-val
It is useful to have your code suggestions for anyone in the future as this would be a more frequent requirement.
Many Thanks
Colin