Newbie question. How do I access data to manipulate it in another column?
Newbie question. How do I access data to manipulate it in another column?
I have retrieved my data and have it displayed in 2 columns. I have managed to add a third column. I want to take the data held in column 2 cell and eventually manipulate it with a cell outside the table result in column 3.
To learn, I have just tried to multiply the 'adjacent column 2 by 10'. i.e 0.00000040 * 10 etc. I get the answer NaN for all rows in column 3. If I do '10 * 10', I get the expected answer of 100 in all rows of column 3. So what am I doing wrong trying to access the wanted data? (item 1). The structure of the data from console.log is:
(80) […]
0: (2) […]
0: "BTC"
1: "0.00000040"
length: 2
<prototype>: Array []
1: (2) […]
0: "XMR"
1: "0.00000020"
length: 2
<prototype>: Array []
2: (2) […]
0: "LTC"
1: "0.00000030"
length: 2
<prototype>: Array []
3: Array [ "SUMO", "0.00000000" ]
4: Array [ "ETN", "75.00000000" ]
5: Array [ "AEON", "0.00000000" ]
//etc, etc to 80
length: 80
<prototype>: Array []
The code is
$(document).ready(function() {
var table = $('#example').dataTable( {
columns: [
{ result: '' },
{ result: '' },
{
"data": null,
//for example
"render": function(data,type,row) { return (data["BTC"] * 10)}
}
],
"ajax": {
"url": "balances.txt", // Load the TXT file
"dataSrc": function (data) {
var result = [];
for(var i in data.balances)
result.push([i, data.balances [i]]);
console.log(result); // show it in the console
return result;
}
}
} );
} );
Thank you for your help
Answers
Found the answer in the end..Alter line 19 and add an extra { '' : '' } in columns.