Je souhaite effectuer des opérations mathématiques dans un tableau en modifiant les valeurs d'entrée dans les cellules et en utilisant l'événement jquery onkeyup.DataTables et jQuery pour effectuer des calculs dans une table
<table id="GVHabvar">
<tbody>
<tr>
<td>
<input id="cantidad" name="cantidad" type="text" class = "calculo">
</td>
<td>
<input id="precio" name="precio" type="text" class = "calculo">
</td>
<td>
<input id="valor" name="valor" type="text">
</td>
</tr>
<tr>
<td>
<input id="cantidad" name="cantidad" type="text" class = "calculo">
</td>
<td>
<input id="precio" name="precio" type="text" class = "calculo">
</td>
<td>
<input id="valor" name="valor" type="text">
</td>
</tr>
<tr>
<td>
<input id="cantidad" name="cantidad" type="text" class = "calculo">
</td>
<td>
<input id="precio" name="precio" type="text" class = "calculo">
</td>
<td>
<input id="valor" name="valor" type="text">
</td>
</tr>
</tbody>
</table>
Ceci est mon essai, mais il ne fonctionne pas bien avec datatables (par exemple avec pagination)
$(document).ready(function() {
var filas = $("#GVHabvar tbody tr");
filas.each(function (index) {
var fila = $(this);
fila.find('.calculo').on('keyup', function() {
var cantidad = ($.isNumeric(fila.find("#cantidad").val())) ? fila.find("#cantidad").val() : 0;
var precio = ($.isNumeric(fila.find("#precio").val())) ? fila.find("#precio").val() : 0;
var valor = parseInt(cantidad, 10) * parseInt(precio, 10);
fila.find('#valor').val(valor);
});
});
});
fonctionne exactement comme je veux! – DavidM