I would like to ask for ideas on how to get the max number from a specific column and return an icon on a different column. I'm using rowCallback, so if there is a maximum number the status will change to active(check mark) and the rest will be x mark.
Here's my code:
"rowCallback": function(row, data, num ) {
if(parseInt(data["num"]) === max ){
$('td:eq(3)', row).html('<a class="btn btn-link btn-success btn-just-icon btn-round"><i class="material-icons">check</i>');
}
else{
$('td:eq(3)',row).html('<a class="btn btn-link btn-danger btn-just-icon btn-round"><i class="material-icons">highlight_off</i>');
}
},
Ideally (if you have access to the data before the HTML is generated) you would compute the maximum value of that column once and pass it to the script.
If you can't do that and need to stay in JS, then the DataTables API has a .column-method that you can use to extract the data. So you can do something like this:
var table = $('#example').DataTable(); // adjust a neccessary to get your table
var max = table
.column( 2 )
.data()
.reduce( function (a,b) {
return Math.max(a,b);
} );