Error average NaN€
Error average NaN€
silens
Posts: 101Questions: 40Answers: 0
I have a field whose value is a number and the sign €, when I do the summation if I do it well but when I do the average it gives me the error.
"footerCallback": function (row, data, start, end, display) {//Aqui meto los subtatales y totales por pagina en el pie de la tabla
var api = this.api(),
data;
var intVal = function (i) {
return typeof i === 'string' ? i.replace(/[\€,]|Kg/g, '') * 1 : typeof i === 'number' ? i : 0;
};
jQuery.fn.dataTable.Api.register( 'average()', function () {
var data = this.flatten();
var sum = data.reduce( function ( a, b ) {
return intVal(a*1) + intVal(b*1); // cast values in-case they are strings
}, 0 );
return (sum) / data.length;
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Can you link to a page showing the issue please? Is
intVal
actually defined in youraverage()
function - its hard to tell from the above.Allan
I'm sorry, right now I can not make a real example. I have lacked some information in the previous example that I put now.
Column 6 from where I do the summation, is a field type: 1.56 €. My problem is that with the € symbol I get an error. IF I remove the symbol, it does it well.
Sounds like you need to remove the Euro symbol. The
intVal
function has a regex which will do that, but I'm not clear if that is actually being used or not. It appears not in your second post above.Allan
De esta forma lo he solucionado. Gracias