Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
La tabla de datos no se muestra correctamente y pierde información

Tengo el siguiente código javascript. Intento obtener información de una API y mostrarla en una tabla de datos. El problema es cuando cargo la página, incluso si tengo 10 elementos por página seleccionada, puedo ver los 102 elementos. Además, cuando cambio de 10 elementos a 25, se elimina toda mi información y aparece el mensaje "No hay registros para mostrar".

 buildlist() function buildlist() { var url = 'http://127.0.0.1:8000/api/angajat-list/' fetch(url).then( res => { res.json().then( data => { console.log(data); let temp = ""; data.forEach((itemData) => { temp += "<tr>"; temp += "<td>" + itemData.idAngajat + "</td>"; temp += "<td>" + itemData.nume + "</td>"; temp += "<td>" + itemData.prenume + "</td>"; temp += "<td>" + itemData.functie + "</td>"; temp += "<td>" + itemData.domiciliuFeroviar + "</td>"; temp += "<td>" + itemData.oreLucrate + "</td>"; temp += "<td>" + itemData.disponibilitate + "</td>"; temp += "<td>" + itemData.programare + "</td>"; temp += "</tr>"; }); console.log(temp) document.querySelector('tbody').innerHTML = temp; } ) } ) } $(document).ready(function () { $('#datatable').dataTable(); });

Este es el código Javascript.

 <div class="card-body"> <table id="datatable"> <thead> <tr> <th>ID ANGAJAT</th> <th>NUME</th> <th>PRENUME</th> <th>FUNCTIE</th> <th>DOMICILIU FEROVIAR</th> <th>ORE LUCRATE</th> <th>DISPONIBILITATE</th> <th>PROGRAMARE</th> </tr> </thead> <tbody id="data"> </tbody> </table> </div>

Este es el código del archivo Html

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Prueba esto

 function buildlist() { var url = 'http://127.0.0.1:8000/api/angajat-list/' fetch(url).then( res => { res.json().then( data => { console.log(data); let temp = ""; data.forEach((itemData) => { temp += "<tr>"; temp += "<td>" + itemData.idAngajat + "</td>"; temp += "<td>" + itemData.nume + "</td>"; temp += "<td>" + itemData.prenume + "</td>"; temp += "<td>" + itemData.functie + "</td>"; temp += "<td>" + itemData.domiciliuFeroviar + "</td>"; temp += "<td>" + itemData.oreLucrate + "</td>"; temp += "<td>" + itemData.disponibilitate + "</td>"; temp += "<td>" + itemData.programare + "</td>"; temp += "</tr>"; }); console.log(temp) document.querySelector('tbody').innerHTML = temp; $('#datatable').dataTable(); } ) } ) } $(document).ready(function () { buildlist(); });

Además, intente usar la funcionalidad ajax de datatable: https://datatables.net/examples/ajax/objects.html

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda