Does search remove nodes from DOM?
Does search remove nodes from DOM?
Hello and thanks for the great product.
I hava a datatable linked to an input search field which works great. The datatable has 3 columns and is similar to:
<tr id="cod_4654" role="row">
<td data-title="desc" class="sorting_1">foobar</td>
<td data-title="Pr." class="sorting_1">5</td>
<td data-title="Qty">
<input name="st_qty" value="0">
</td>
</tr>
... a lot of other rows
Now the issue: I use the following script to calculate the sum of total quantity adding Qty value row by row.
$("input[name=st_qty]").change(function () {
var sum = 0;
$("input[name=st_qty]").each(function() {
sum += Number($(this).autoNumeric('get')); // <-- ISSUE with filtered rows!
// (not considered)
});
$("span#grand_total").autoNumeric('set', sum);
});
The problem is that when I filter the results, rows are removed from the DOM and the sum doesn't consider these removed rows with their respective qty
value.
Can you suggest a solution or workaround?
This question has an accepted answers - jump to answer
Answers
You need to use the DataTables API -
rows().nodes()
for example to get the nodes.Allan