Footer callback with multiple columns

Footer callback with multiple columns

rudeigercrudeigerc Posts: 4Questions: 1Answers: 0

I've read the example of footer callback which calculates the total of one specific column.
Now suppose my table has two columns: quantity and price, how could I calculate the sum of (quantity times price) according to the api? I have noticed that the reduce function could not work on multiple columns. Thank you!

This question has an accepted answers - jump to answer

Answers

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Are your numbers static? If so, I would apply the row multiplication before you display (creating another column) the table, then you can use the summing in the callback that you are referring to.

  • rudeigercrudeigerc Posts: 4Questions: 1Answers: 0

    Hi bindrid, thank you for answering the question. Actually, I'm using DataTables to show the schema in the database, and maybe an extra column shown in the table is not a good option.

  • bindridbindrid Posts: 730Questions: 0Answers: 119
    edited May 2017 Answer ✓

    So basically yes. In that case, it would actually be faster to do the calculations on the raw data before pushing into the table.

    I did make this which might be of help
    http://jsbin.com/putiyep/edit?js,output

  • rudeigercrudeigerc Posts: 4Questions: 1Answers: 0

    Thank you very much, bindrid. I would take a look at the link!

  • rudeigercrudeigerc Posts: 4Questions: 1Answers: 0

    @bindrid Finally I add a column to multiply the sum and set it as invisible, thanks a lot!

This discussion has been closed.