1
I have this function which sums the fields of a column of table
and works perfectly:
let result = 0;
let columns = $("#tablepesquisaprodutos tr td:nth-child(" + 8 + ")");
columns.each(i => {
result += parseFloat($(columns[i]).html().replace(/\./g, '').replace(',', '.'));
});
But the need arose to add only the fields where column 19 is true, how can I do all this in the same function ?
Detail: In this case is a table
dynamic, which I fill by jquery.
This is the HTML of table
<table class="table table-responsive table-hover table-striped" id="tablepesquisaprodutos" style="font-size:12px;">
<thead>
<tr>
<th></th>
<th>Código</th>
<th>Descrição</th>
<th>Qtd</th>
<th>Preço Un.</th>
<th>Desc %</th>
<th>Desc R$</th>
<th>Total</th>
<th>ICMS</th>
<th>Alíquota</th>
<th>V.ICMS</th>
<th>%ISS</th>
<th>V.ISS</th>
<th>%IPI</th>
<th>V.IPI</th>
</tr>
</thead>
<tbody><tr class="item"><td><input type="checkbox" class="link-check" onchange="cbChange(this);"></td>
<td>P00082</td>
<td>teste</td>
<td>1</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td>1</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td>0,00</td>
<td style="display: none;">1</td>
<td style="display: none;">82</td>
<td style="display: none;">08/11/2018</td>
<td style="display: none;">true</td>
</tr></tbody>
</table>
You can use the jQuery filter. .
– Andre
@Andre I fill this table dynamically by jquery, I will edit the answer.
– Mariana
Open the developer tools and copy the already rendered HTML from your page. The solution will depend on how this "false" is represented. What does this "Type" variable contain? Is it a boolean? A checkbox?
– Andre
It is string type, I need to check if it is true or false. As I explained the table is filled dynamically.
– Mariana
But no matter if the table is populated dynamically, you can take its HTML with the developer tools. Add a row to it, press F12, locate the table in your HTML and copy it.
– Andre
@Andre ready. I edited the question. I need to add the total column, according to the condition of the last column, if it is false and if it is true.
– Mariana