Fill with a Script isnt working
Fill with a Script isnt working
JulitoM3
Posts: 1Questions: 1Answers: 0
Hi everyone, im trying to fill <td> when the data from a query is null, with space or without space but my script is not working if i use datatable. why is this happening? thanks a lot.
const celdas = document.querySelectorAll('tbody td')
celdas.forEach(celda => {
let value = celda.innerHTML.trim()
if((value || '').length === 0) celda.innerHTML = 'VACIO'
})
$(document).ready(function() {
$('#tableId tfoot th').each( function () {
var title = $(this).text();
$(this).html( '<input type="text" placeholder="'+title+'" />' );
} );
var table = $('#tableId').DataTable({
"scrollX": true,
dom: "Bfrtip",
responsive: true,
buttons:[
{
extend: 'excel',
text: 'Crear Excel',
},
{
extend: 'copy',
text: 'Copiar',
}
],
"lengthMenu": [ [-1,5, 10, 25, 50], ["TODOS",5, 10, 25, 50] ],
"language": {
buttons:{
copyTitle: 'Datos copiados',
copySuccess:{
1 : 'Copiado 1 fila, ahora puedes pegar en excel',
_ : 'Se copiaron %d filas, ahora puedes pegar en excel'
}
},
search: 'Busqueda general:',
"lengthMenu": "Mostrando _MENU_ registros por pagina",
"zeroRecords": "Sin datos",
"info": "Mostrando _PAGE_ de _PAGES_",
"infoEmpty": "Sin registros",
"infoFiltered": "(filtrados de _MAX_)",
paginate: {
first: 'Primero',
previous: 'Anterior',
next: 'Siguiente',
last: 'Último',
}
}
});
table.columns().every( function () {
var that = this;
$( 'input', this.footer() ).on( 'keyup change', function () {
if ( that.search() !== this.value ) {
that
.search( this.value )
.draw();
}
} );
} );
} );
This discussion has been closed.
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin