Vote count:
0
I've been trying to figure out how to append an html table with a column of data. A button will be clicked that will take existing data column in the table, save to an array, then do some math on it, then spit it back out as the last column in the table.
Here's the code I've been trying:
var c = $("#dvCSV tr:nth-child(2) td").length;//find number of columns in the table
var myArray = new Array();
$("#dvCSV tr td:nth-child(3)").each(function(i){
myArray.push($(this).text());
});
myArray.splice(0,2);
$("#dvCSV tr:first").append("<td>Th</td>");
var n=0;
$('#dvCSV').find('tr').each(function(){
myArray[n]= "<td>" + (myArray[n]*0.01) + "</td>";
$(this).append(MyArray[n]);
n=n+1;
});
Here's a fiddle I have been working on.
I thought I could nest in the array values into the each function, but it's not working right. I can't seem to find any other example out there to get it to work.
If it's possible to work with the values in the table without first converting to an array, even better.
The td values in a column (work will be done on all columns with values) need to have some math function worked on it. So it's taking that td value * f(x) then placing that value on the same row as the original value in a new column to the right.
Any help would be appreciated.
JQuery - Adding an html table column to end of table based on array data
Aucun commentaire:
Enregistrer un commentaire