footerCallback
footerCallback
Hi every body,
The function Math.max is running well
footerCallback: function ( row, data, start, end, display ) {var api = this.api(),data ; var intVal = function (i) {return typeof i === 'string' ?i.replace( /[€,]/g, '' ) * 1 : typeof i === 'number' ? i : 0;};var Salary = api.column(10,{ search: 'applied' }).data().reduce( function (a, b) {return Math.max(a,b);}, 0 );$( api.column(10).footer() ).html(DataTable.render.number('’', '.', 2, '$ ', '').display(Salary));},
The function Math.min is always giving zéro.
footerCallback: function ( row, data, start, end, display ) {var api = this.api(),data ; var intVal = function (i) {return typeof i === 'string' ?i.replace( /[€,]/g, '' ) * 1 : typeof i === 'number' ? i : 0;};var Salary = api.column(3,{ search: 'applied' }).data().reduce( function (a, b) {return Math.min(a,b);}, 0 );$( api.column(3).footer() ).html(DataTable.render.number('’', '.', 2, '$ ', '').display(Salary));},
I cannot fin the reason why it's not giving the minimum of the column.
This question has accepted answers - jump to:
Answers
I reformatted the footerCallback (so its easier to read) and added a console.log statement so you can see what is happening:
https://jsbin.com/cuqapipogo/1/edit?html,output
Since you are starting with
0
as the initial value its always the minimum value. Change this to number higher than what your data will be for the Math.min() function to work.Kevin
I changed the table to show the salary column.
https://jsbin.com/mecimomuho/1/edit?html,output
It works with a higher start value as the minimum. But if you don't know it ?
Is there a way to get the result without knowing in advance what is approximately the minimum ?
I tryed to put a hight number, 1 Mio to be sure, but it slow down the output.
An other solution would be to get first the maximum and use it as starting ?
Philippe
What do you think ?
That works. Or you could use
Infinity
. Or perhaps better would be to do:Personally I prefer this option - I suspect it will be much faster.
Allan
Thanks for your proposal and you are probably right.
But I don't know the total code for the footerCallback with your smart proposal.
Thanks in advance.
Something like this:
Kevin
Thanks Kevin, it works perfectly
Thanks Allan