Footercallback - skip dash signs without converting to 0
Footercallback - skip dash signs without converting to 0
Hello,
Thank you for taking the time to read this.
I know similar questions have been posted and I have spent some hours browsing all options before asking this question but I could not implement any solution.
I have a table and I am trying to calculate the average in the footer. I have managed to implement the average however, I have some td that do not have any data and therefore need to be left empty. I have entered the sign - in those cells but the code I have now, converts the dash sign to 0 which ruins the calculation of the values from the other cells. (I need accurate calculation of the values from the other cells).
Therefore, my question is: What do I need in order to completely skip/ignore those cells from the calculation and avoid converting them to 0?
Please see this link for the test case:
https://live.datatables.net/fuporifi/3/edit
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
This question has an accepted answers - jump to answer
Answers
Easiest option would probably just be to check the value in the reduce function:
Allan
Hi,
Thanks for the answer. I tried adding it just to test but it is not working.
However, I am not trying to convert the - to 0. If the value is 0, the calculation from the column will not be correct. I need the code to completely ignore the empty cell.
Since you are calculating the average then keep track of the number of skipped/empty rows in the if statement.
Since you are calculating the average from the rows on the page, for example:
You should get the number of rows using the same
selector modifier
. Change:To:
Here is the updated example with Allan's suggestion plus the above two changes:
https://live.datatables.net/fuporifi/7/edit
Kevin
Thank you so much for you help. This works