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

137
Visualizações
The data is not inserted correctly in the table tbody tag

I'm having a problem setting the body in the dynamic content table.

In fact, thead has been set correctly, but most likely the problem is the tbody; the header of the columns is perfectly displayed, but the content is not.

See image below (Nessun dato presente nella tabella --> No data in the table)

Can anyone kindly help me?

var allart = JSON.parse(this.responseText);
                console.log(allart);
                var tbdy = document.createElement('tbody');
                allart.Items.forEach(function (item) {               
                    let child = document.createElement("tr");
                    child.innerHTML = `
                    <td>${item.id}</td>
                    <td>${item.titolo}</td>
                    <td>${item.marca}</td>
                    <td>${item.immagine}</td> 
                    <td>${item.sezione}</td>
                    <td>${item.data}</td>
                    `;
                    table.appendChild(child);
                })
                tbdy.appendChild(tr);
                table.appendChild(tbdy);
                
$(document).ready(function () {
            $('#my-table').DataTable({
                "pagingType": "full_numbers",
                "lengthMenu": [5, 10, 20, 50, 100, 200, 500],
            });
            $('.dataTables_length').addClass('bs-select');
        });
<table id="my-table" class="row-border hover" width="90%">
        <thead>
            <tr>
                <th class="th-sm">Id</th>
                <th class="th-sm">Titolo</th>
                <th class="th-sm">Marca</th>
                <th class="th-sm">Immagine</th>
                <th class="th-sm">Sezione</th>
                <th class="th-sm">Data</th>

            </tr>
        </thead>

    </table>

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

0

you need to append tr with tbody inside the loop.

allart.Items.forEach(function (item) {
    let child = document.createElement("tr");
    child.innerHTML = `
                <td>${item.id}</td>
                <td>${item.titolo}</td>
                <td>${item.marca}</td>
                <td>${item.immagine}</td> 
                <td>${item.sezione}</td>
                <td>${item.data}</td>
                `;
    tbdy.appendChild(child);
})
table.appendChild(tbdy);
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