Multiply all the rows of a specific column and show result on footer
Multiply all the rows of a specific column and show result on footer
Hi,
I’m trying to multiply all the rows of a specific column (for example Salary column) to show the result in the footer, but I could not find a solution.
I want to do the same as the example https://datatables.net/examples/advanced_init/footer_callback.html
But, instead of doing SUM of the rows of a specific column I want to do the multiplication operation, as if I change “+” Sign with “*” Multiply sign, in the footer it gives as result 0.
Any idea how to achieve that?
Thank in advance.
This question has an accepted answers - jump to answer
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,
Thank you for the quick reply, the test case link is:
https://live.datatables.net/larozame/1/edit?html,css,js,output
As you can see the result of the multiplication gives 0.
Regards
In both of your reduce() functions, the value of a is always 0.
I don't know that func, so can't help further.
@tangerine, as you can see if you change "*"(multiplication operator) with "+"(addition operator) it will give you the correct result in both functions. The issue that I have is that with multiplication does not work.
You need to use a start value of
1
otherwise everything is multiplied with0
.https://live.datatables.net/larozame/6/edit
Kevin
Thank you very much @kthorngren , it very appreciated, it seems to be working perfectly.