Quiero agregar un número de índice a cada fila en una tabla automáticamente, como el de la captura de pantalla que obtuve del sitio de bootstrap aquí , probé varias soluciones pero seguí obteniendo un índice de -1 para todas las filas, realmente lo haría. agradezco la ayuda, gracias.
¿Esto funciona para tí?
// tbl is the table var rows = tbl.rows; n = 1; for (i=0; i<rows.length; i++) { row = rows[i]; f = row.firstElementChild; if (f) { el = document.createElement(f.tagName); el.innerHTML = (f.tagName == "TH") ? "#" : n; row.insertBefore(el, f); if (f.tagName != "TH") n++; } }