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

200
Views
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
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!