Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
Load datatables with async fetch

i'm trying to use datatables plugin with data from api, i get the data with fetch javascript, do i need async await to store the data into datatables ? the result is no error just it won't show the data, i already put the datatables inialization inside the async function how do i do it properly ?

html code :

<table id='myTable' class="table table-inverse table-danger">
    <thead>
    <tr>
        <td>Index</td>
        <td>Value</td>
    </tr>
    </thead>
    <tbody class"demo">
    </tbody>
</table>

fetch code :

  var url = 'http://192.168.150.155:9900/meikel/_search/';

async function getapi(url) {

      const response = await fetch('http://192.168.150.155:9900/meikel/_search', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + btoa('elastic:7d76bd7b7ca96905e0195b2f3ecd1449b9b98f58be7c71ed7549739990fad6a8')
    },
    body: JSON.stringify({
        size: 10000,
        "query": {
            "match_all": {}
        }
        })
    })

      var data = await response.json();
      
      if (response) {

      }

      var i = 0;

      for(let i = 0; i < data.hits.hits.length; i++) {

      }

      let name = "";
      let company = "";

      for (let i = 0; i < data.hits.hits.length; i++) {
        name += "<tr '> <td><img style='width: 50px;' src='"+ data.hits.hits[i]._source.imagepath + "'></td>"+ "<td><a href='employees/?id="+ data.hits.hits[i]._id +"' class='text-dark text-decoration-none'><p href='employees/'>" + data.hits.hits[i]._source.name + "</p></a></td>"  + "<td>" + data.hits.hits[i]._source.nip + "</td>" + "<td>" + data.hits.hits[i]._source.companycode + "</td>" + "<td>" + data.hits.hits[i]._source.organization.division + "</td>" + "<td>" + data.hits.hits[i]._source.employee.status + "</td>" + " </tr>";

      }

      document.getElementsByClassName("demo")[0].innerHTML = name;

      $(document).ready( function () {
          $('#myTable').DataTable();
      } );

      }

getapi(url);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda