Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda