0
how to perform the automatic sum of a specific column? I tried with the script below using Jquery, but without success. The total value in the column to be filled is in the last . (space is blank).
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Minha Vida</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src=""></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('table thead th').each(function(i) {
calculateColumn(i);
});
});
function calculateColumn(index) {
var total = 0;
$('table tr').each(function() {
var value = parseInt($('td', this).eq(index).text());
if (!isNaN(value)) {
total += value;
}
});
$('table tfoot td').eq(index).text('Total: ' + total);
}
</script>
</head>
<body>
<table id="sum_table" style="width:50%" align="center">
<tr bgcolor="#FFFF00" class="header-table">
<th>Corretora</th>
<th>Ação</th>
<th>Qtde</th>
<th>Valor</th>
</tr>
<tr>
<td><img src="imagens/rico-corretora-logo.jpg" width="100" /></td>
<td>ODPV3</td>
<td>100</td>
<td>2.000</td>
</tr>
<tr>
<td><img src="imagens/rico-corretora-logo.jpg" width="100" /></td>
<td>WEGE3</td>
<td>100</td>
<td>1.800</td>
</tr>
<tfoot>
<tr>
<th colspan=3>Total Investido</th>
<td></td>
</tr>
</tfoot>
</table>
</body>
</html>