Calculating and displaying % in column of a generated sum
Calculating and displaying % in column of a generated sum
dennisbartel
Posts: 5Questions: 0Answers: 0
in DataTables
Is it possible to have a column calculate the percentage of a sum that was generated by using .data().sum() in a drawCallback:. This changes upon draw / filter. For Example the sum of 10 rows would be 10000 and if one of the rows had 2000 for data the percent column would read 20%. This percentage would change depending on the number of records. Currently using dataTables 1.10.8.
This discussion has been closed.
Replies
Yes, it is possible.
But, I would suggest using it in the footerCallBack instead of the drawCallBack as the footer seems to be the better place to determine the displayed contents.
Please see this fiddle, choose A, B or C in the search box to filter only the displayed results.
http://jsfiddle.net/glenderson/of1xo61o/
You might also be interested in this example and modifying that to suit your needs.
Allan
Thank you glenderson i was able to solve it using the code you provided. As I have data coming in through ajax i made a few tweaks to get it to work. Data undefined for the column with defaultcontent: " ",
and for populating the column per row defined the data from the JSON.
Thank you glenderson for the solution, I really appreciate your help. Thank you Allan.