Answer the question
In order to leave comments, you need to log in
NaN: how to tidy up data in JS?
Hey!
I'm currently busy implementing the Totals count in dataTables using a function like this.
var stat_options = $.extend({
"sAjaxSource": "/dashboard/graph/",
"aoColumns": [
{ "mData": "date" },
// {"mData":"clicks"},
{ "mData":"unique_clicks" },
{ "mData":"events_count" },
{ "mData":"approved" },
{ "mData":"pending" },
{ "mData":"rejected" },
{ "mData":"cpc" },
{ "mData":"ltr" },
{ "mData":"approval_rate" },
// {"mData":"total_revenue"},
// {"mData":"rejected_revenue"},
{ "mData":"pending_revenue" },
{ "mData":"approved_revenue" }
],
"fnFooterCallback": function( nRow, aaData, iStart, iEnd, aiDisplay ) {
var iClicks = 0
var iConv = 0
var iPendingRevenue = 0
var iApprovedRevenue = 0
for ( var i=0 ; i<aaData.length ; i++ )
{
iClicks += aaData[i][1]*1;
iConv += aaData[i][2]*1;
iPendingRevenue += aaData[i][9]*1;
iApprovedRevenue += aaData[i][10]*1;
}
var nCells = nRow.getElementsByTagName('th');
nCells[1].innerHTML = parseInt(iClicks);
nCells[2].innerHTML = parseInt(iConv);
nCells[9].innerHTML = parseInt(iPendingRevenue);
nCells[10].innerHTML = parseInt(iApprovedRevenue);
}
}, tables_options);
Answer the question
In order to leave comments, you need to log in
Since you have such a patchy response, parseInt needs every element in the loop. Now you are already parsing a string, glued together from all elements.
-------------------------------------------------- -----------
Sorry, the first time I looked inattentively, the cast to number is already in the loop.
-piece of aaData, then the problem is that this is an object containing objects, you are trying to sort through it as an array containing objects with arrays. and it doesn't even have a length field.
for (i in aaData){
iClicks += parseInt(i['unique_clicks'], 10);
........
}
Response example
"2013-06-17": {"payout": "7900.000000", "ltr": "2.9277", "pending_revenue": 1500.0, "leads": "32", "events_count": 38, "cpc" : "7.23", "rejected": 3, "approved_revenue": 7900.0, "unique_clicks": "1093", "date": "2013-06-17", "approval_rate": 84, "approved": 32, " pending": 3, "rejected_revenue": 1000.0},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question