Carpeta js
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
const table = $('#tablaProductos').DataTable({
|
||||
paging: true,
|
||||
searching: true,
|
||||
ordering: true,
|
||||
pageLength: 6,
|
||||
lengthChange: false,
|
||||
info: true,
|
||||
autoWidth: false,
|
||||
|
||||
columnDefs: [
|
||||
{ orderable: false, targets: [- 1, - 2] }
|
||||
],
|
||||
|
||||
dom:
|
||||
"<'row mb-3'<'col-md-8'f><'col-md-4 text-end'l>>" +
|
||||
"<'row'<'col-12'tr>>" +
|
||||
"<'row mt-3'<'col-md-5'i><'col-md-7'p>>",
|
||||
|
||||
language: {
|
||||
search: "",
|
||||
searchPlaceholder: "Buscar productos...",
|
||||
zeroRecords: "No se encontraron productos",
|
||||
info: "Mostrando _START_ a _END_ de _TOTAL_ productos",
|
||||
infoEmpty: "No hay productos para mostrar",
|
||||
infoFiltered: "(filtrado de _MAX_ productos totales)",
|
||||
paginate: {
|
||||
next: "›",
|
||||
previous: "‹"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Mover buscador al bloque izquierdo
|
||||
|
||||
$('.dataTables_filter')
|
||||
.addClass('d-flex align-items-center gap-2')
|
||||
.appendTo('#filtrosIzquierda');
|
||||
|
||||
$('#filtrosIzquierda').append($('#columnFilter'));
|
||||
|
||||
const searchInput = $('.dataTables_filter input');
|
||||
|
||||
$('#columnFilter').on('change', function () {
|
||||
const colIndex = $(this).val();
|
||||
|
||||
table.search('').columns().search('').draw();
|
||||
|
||||
searchInput.off('keyup').on('keyup', function () {
|
||||
if (colIndex === "") {
|
||||
table.search(this.value).draw();
|
||||
} else {
|
||||
table.column(colIndex).search(this.value).draw();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// SUBMIT (problema de checkbox)
|
||||
|
||||
$('form').on('submit', function () {
|
||||
|
||||
const form = this;
|
||||
|
||||
// Obtener TODOS los checkboxes marcados del DataTable (no solo los visibles)
|
||||
|
||||
const checked = table.$('input[name="ids[]"]:checked');
|
||||
|
||||
// Eliminar cualquier ids[] previo agregado dinámicamente
|
||||
|
||||
$(form).find('input[name="ids[]"][type="hidden"]').remove();
|
||||
|
||||
// Agregar hidden inputs reales al form
|
||||
|
||||
checked.each(function () {
|
||||
$('<input>')
|
||||
.attr('type', 'hidden')
|
||||
.attr('name', 'ids[]')
|
||||
.val($(this).val())
|
||||
.appendTo(form);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user