I have a problem sending the value of input
in state checked
to my controller, unfortunately I only send the values of the page where I am at that moment and not all the pages where I have selected a checkbox
, what I mean with pages is because I'm using the datatables
pagination.
My code is as follows:
<div class="container">
<h2>Ventas</h2>
<form action="venta.php" method="POST">
<table id="inventario" class="table table-hover table-bordered table-condensed">
<thead>
<tr>
<th><i class="fa fa-check"></i> Selección articulo</th>
<th><i class="fa fa-list-ol"></i> Cantidad</th>
<th><i class="fa fa-building"></i> Marca</th>
<th><i class="fa fa-list"></i> Categoria</th>
<th><i class="fa fa-usd"></i> Precio</th>
</tr>
</thead>
<tbody>
<?php foreach ($articulos as $articulo): ?>
<tr>
<td><label class="checkbox-inline"><input name="articulos[]" type="checkbox" value="<?php echo $articulo['id']; ?>"><?php echo $articulo['nombre']; ?></label></td>
<td><?php echo $articulo['cantidad']; ?></td>
<td><?php echo $articulo['categoria']; ?></td>
<td><?php echo $articulo['marca']; ?></td>
<td><?php echo number_format($articulo['precio_u']); ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<input type="submit" class="btn btn-warning" name="vender" value="Vender">
</form>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#inventario').DataTable();
var dataArr = [];
$('tr').filter(':has(:checkbox:checked)').each(function() {
dataArr.push($(this).find('input').eq(0).val());
console.log(dataArr);
});
} );
</script>
As some of you could appreciate, I tried to make a script to collect all the values and send them to my controller. However, I can not do it. I'm not very good with the JS.
I found that someone did this snippet for this problem however I do not know how to complement it.
var rows = $(('#datatable')
.rows({ 'search': 'applied' })
.nodes()).filter(':has(:checkbox:checked)');//busca todos los registros del datatable
rows.each(function(index,elem){
//cada row es un tr
console.log($('datatable').row(elem).data());
});
If it is necessary to use ajax to send all the values of the selected checkboxes, I have no problem.