how to Dynamically update footer with total, min and Average of datatable columns

how to Dynamically update footer with total, min and Average of datatable columns

SamkSamk Posts: 6Questions: 2Answers: 0

Link to test case: https://live.datatables.net/zalitado/3/edit
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem: unable to dynamically update totals in footer as the input text changes in the columns. and looking for a function to generate average and min of columns.

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    Answer ✓

    You need to keep up with the input value by updating it when changed by updating the document. And you need to have Datatables updates its data cache to know about the change using cell().invalidate(). Last you will need to use draw(), with the page parameter to stay on the same page, to have footerCallback to run. See updated example:
    https://live.datatables.net/zalitado/5/edit

    Kevin

  • SamkSamk Posts: 6Questions: 2Answers: 0

    thanks very much Kevin, oddly the column 3 doesn't update, although the data type is converted to numeric. is the column somehow being set to string after the redraw, seem unlikely though

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    You can use the v2 multi-row header / footer API to be able to pick out and update the other rows in the footer: https://live.datatables.net/zalitado/10/edit .

    I've used plug-in API methods for average and min there as well.

    The data type issue doesn't appear to effect funcationlity?

    Allan

  • SamkSamk Posts: 6Questions: 2Answers: 0

    thanks allan, giant leap!!
    . ive made some changes to compensate for zero values when calc'ing average and min values. im now stuck with a search or vlookup type behaviour that that i need to populate the cpty with the min, max, and average values that have been calc'd. testcase -> https://live.datatables.net/zalitado/13/edit

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I've added a reply to your other thread on that topic.

    Allan

Sign In or Register to comment.