Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
¿Cómo construyo una tabla dinámicamente en este escenario?

Tengo una variable que contiene una matriz de matrices. Es un código analizado de un archivo de Excel.

Quiero cargar mi archivo y construir la tabla, lo he intentado así:

 tabela.forEach((elem, index) => { console.log(elem[0], index[1]) const row = tableBody.insertRow(index) const employeeCell = row.insertCell(0) let content = document.createTextNode(elem[0]) employeeCell.appendChild(content) })

y así:

 for (let i = 1; i < tabela.length; i++) { const row = tableBody.insertRow(tabela[1]) const employeeCell = row.insertCell(0) let content = document.createTextNode(tabela[0]) employeeCell.appendChild(content) }

pero obtengo resultados extraños con ambos.

Realmente quiero entender lo que estoy haciendo, pero tengo problemas.

La variable tabela es un arreglo de 13 elementos, cada elemento es un arreglo de 7 elementos.

¿Alguien sabe qué estoy haciendo mal, cómo hacerlo, así que construyo una tabla completa a partir del código analizado de la variable "tabela"?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Debe recorrer los elementos de la row para agregar una celda para cada elemento.

 tabela.forEach(elem => { const row = tableBody.insertRow(); elem.forEach(item => { const cell = row.insertCell(); cell.innerText = item; }); })

about 4 years ago · Juan Pablo Isaza Report

0

La siguiente demostración muestra cómo puede realizar su tarea usando jQuery .

 const tablea = [ [30,45,2,9,0], [455,65,0,5,78], [1,1,4,4,6] ]; let $tableBody = $('#xdata tbody'); $tableBody.html( tablea.map(row => $('<tr/>').html( row.map(cell => $('<td/>').html( cell )) )) );
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table id="xdata"><tbody></tbody></table>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!