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

CristianESCristianES Posts: 6Questions: 2Answers: 0
edited March 2023 in Free community support

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • CristianESCristianES Posts: 6Questions: 2Answers: 0
    edited March 2023

    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

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    In both of your reduce() functions, the value of a is always 0.
    I don't know that func, so can't help further.

  • CristianESCristianES Posts: 6Questions: 2Answers: 0

    @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.

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954
    Answer ✓

    You need to use a start value of 1 otherwise everything is multiplied with 0.
    https://live.datatables.net/larozame/6/edit

    Kevin

  • CristianESCristianES Posts: 6Questions: 2Answers: 0

    Thank you very much @kthorngren , it very appreciated, it seems to be working perfectly.

Sign In or Register to comment.