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

164
Visualizações
How to locally change order of elements in table using scripts?

I'm trying to locally edit the order of an element within a table so that whenever I open the webpage the table shows the order I want. Using Chrome's element inspector I was able to change the order by dragging these elements and arranging them. Is there any script that helps me maintain this desired order without having to manually change it every time?

Original table structure:

<table class="zebra" id="gamesTable">
<tbody>
<tr class="platinum" data-psnpp-processed="true"> (element 1)
<tr class="platinum" data-psnpp-processed="true"> (element 2)
<tr class="platinum" data-psnpp-processed="true"> (element 3)
</tbody>
<table>

Desired table structure:

<table class="zebra" id="gamesTable">
<tbody>
<tr class="platinum" data-psnpp-processed="true"> (element 2)
<tr class="platinum" data-psnpp-processed="true"> (element 1)
<tr class="platinum" data-psnpp-processed="true"> (element 3)
</tbody>
<table>

Is there any way to run this locally edit using scripts?

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

0

You can add data-order to the rows and then sort it with javascript. Try this

<table class="zebra" id="gamesTable">
    <tbody>
        <tr class="platinum" data-psnpp-processed="true" data-order="2"> <td>(element 1)</td></tr>
        <tr class="platinum" data-psnpp-processed="true" data-order="1"> <td>(element 2)</td></tr>
        <tr class="platinum" data-psnpp-processed="true" data-order="3"> <td>(element 3)</td></tr>
    </tbody>
</table>

<script>
  let parent = document.querySelector("#gamesTable tbody");
  let rows   = parent.querySelectorAll("tr");
  let sorted = Array.from(rows).sort(function(a, b) {
      let c = a.dataset.order, d = b.dataset.order;
      return c < d ? -1 : c > d ? 1 : 0;
  });

  sorted.forEach(item => parent.append(item));
</script>

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