DataTable - how to show _TOTAL_ token as a percentage of _MAX_ token

DataTable - how to show _TOTAL_ token as a percentage of _MAX_ token

theHearsetheHearse Posts: 2Questions: 1Answers: 0
edited June 2023 in Free community support

I'm trying to include a calculation within DataTable that shows to the user the "TOTAL"(filtered row count token) as a percentage of "MAX' (table row count token) and for the result to be returned to the "infoFiltered" attribute.

Is this possible and if so how?

Thanks.

Richard.

This question has an accepted answers - jump to answer

Answers

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

    I don't believe you can use calculations with language.info. Try using infoCallback instead.

    Kevin

  • theHearsetheHearse Posts: 2Questions: 1Answers: 0
    edited June 2023

    Thanks. I'm now using infoCallback and it works as expected with the percentage rounded to 1 decimal place. Very useful.

    var table = $('#example').DataTable({
        infoCallback: function( settings, start, end, max, total, pre ) {
           if (total == 0) return "None found";
           return 'Showing '+total+' of '+max+' or '+ Math.round(((total/max)*100) *10)/10 +'%';},
        }
    })  
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Sign In or Register to comment.