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

243
Views
Cómo ordenar una tabla html priorizando números e ignorando cadenas

Tengo una tabla html como esta y una función de clasificación para ordenar la columna "r" numéricamente.

función:

 function sortTablee(dir) { var table, rows, switching, i, x, y, shouldSwitch, switchcount = 0; table = document.getElementById("myTable"); switching = true; while (switching) { switching = false; rows = table.rows; for (i = 1; i < (rows.length - 1); i++) { shouldSwitch = false; x = rows[i].getElementsByTagName("TD")[1]; y = rows[i + 1].getElementsByTagName("TD")[1]; if (dir == "asc") { if (x.innerHTML > y.innerHTML) { shouldSwitch = true; break; } } else if (dir == "des") { if (x.innerHTML < y.innerHTML) { shouldSwitch = true; break; } } } if (shouldSwitch) { rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); switching = true; switchcount++; } } }

Todo está bien al ordenar de manera descendente, pero al ordenar de manera ascendente, en lugar de mostrar

 2.5 4 5

prioriza los guiones, mostrando los números en la parte inferior. ¿Hay alguna manera de priorizar siempre y mostrar los números en la parte superior y luego llegar a los guiones?

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

0

Tal vez verifique el '-' y cámbielo siempre. Entonces todos - son empujados hacia atrás

 function sortTablee(dir, w, r, ff, gg) { var table, rows, switching, i, x, y, shouldSwitch, switchcount = 0; table = document.getElementById("myTable"); switching = true; while (switching) { switching = false; rows = table.rows; for (i = 1; i < (rows.length - 1); i++) { shouldSwitch = false; x = rows[i].getElementsByTagName("TD")[1]; y = rows[i + 1].getElementsByTagName("TD")[1]; if (dir == "asc") { if(x.innerHTML == '-'){ shouldSwitch = true; break; } else if (x.innerHTML > y.innerHTML) { shouldSwitch = true; break; } } else if (dir == "des") { if(x.innerHTML == '-'){ shouldSwitch = true; break; } else if (x.innerHTML < y.innerHTML) { shouldSwitch = true; break; } } } if (shouldSwitch) { rows[i].parentNode.insertBefore(rows[i + 1], rows[i]); switching = true; switchcount++; } } }
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!