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

194
Visualizações
How to sort a tree table by rows (header on the left) with no <thead>

I want to sort a tree table not by columns but rows, its header is on the left in the tree part. My tree table looks like this the tree table plugin I used.

And the code is something like this

  <table>
      <tr data-node-id="index">
        <th>Index</th>
        <td>...</td>
        <td>...</td>
      </tr>
      <tr data-node-id="patient">
        <th>Patient Characteristics</th>
      </tr>
      <tr data-node-id="name" data-node-pid="patient">
        <th>Name</th>
        <td>...</td>
        <td>...</td>
      </tr> 
      <tr data-node-id="DOB" data-node-pid="patient">
        <th>DOB</th>
        <td>...</td>
        <td>...</td>
      </tr> 
      <tr data-node-id="age" data-node-pid="patient">
      ...

enter image description here

There is no <thead> part, so many sorting methods not work well on this table. I'm new to javascript sort of things, and have no idea if this is easy to do. But I did not find methods for this situation online, so I try to ask for help.

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

0

First, access the table element:

var table = document.getElementById("table").children[0]; // You can just add an id to the table

Here is a function for sorting by row:

function sortRow(rowNum) { // rowNum is index of row: for example, name is 2
var answerArray = [];
for (i = 1; i < table.children[rowNum].children.length; i++) {
    answerArray.push(table.children[rowNum].children[i].innerHTML);
}
return answerArray;

This function takes in the row number, and returns an array of all values in the row.

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