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

196
Visualizações
React sortable tree does not respect treeIndex order

I am trying to persist the order of Nodes in the tree using react-sortable-tree (https://github.com/frontend-collective/react-sortable-tree), for Example

 - Label 1
      - Label 2
      - Label 3

Changing the order of Label 3 to Label 2 in the following way and also passing the treeIndex,

 - Label 1
      - Label 3
      - Label 2

Upon setting the updated state and reloading the page tree structure does not follow treeIndex order.

Things I have tried:

I have tried the following using the utils of react sortable tree (https://github.com/frontend-collective/react-sortable-tree/blob/master/src/utils/tree-data-utils.js)

I have tried converting my current tree to flat structure using getFlatDataFromTree() and then making the treeIndex changes that are required and then converting the flat data back to tree structure using the same util library with getTreeFromFlatData() but the sequence with respect to treeIndex is not considered.

I already have tree data stored in treeData,

here labelNodes contain the path of each node of the tree. So I am looping over them and assigning the correct order.

Code:

flatTree.forEach(treeNode => {
        labelNodes.forEach(element => {
          if (treeNode.node.id === element.id) {
            treeNode.path = element.path;
            treeNode.treeIndex = element.treeIndex;
          }
          return true;
        });
      });

const getParentKey = node => {
        if (node.parentNode) {
          return node.parentNode.id;
        }
        return 0;
      };

const sortedFlatTree = flatTree.sort((a, b) => a.treeIndex - b.treeIndex);

const treeConversion = getTreeFromFlatData({
        flatData: sortedFlatTree,
        getParentKey,
      });

treeConversion does not maintain the sorted order.

about 4 years ago · Juan Pablo Isaza
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