Author Topic: Bug in moveNode event or Tree.getRoots()  (Read 180 times)

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Bug in moveNode event or Tree.getRoots()
« on: May 27, 2024, 02:33:59 am »
In the moveNode event, in the ui we get 3 array values in "args":

0: The nodes that have been moved
1: The new parent (null if root)
2: The new position starting from 1 within the siblings

In the function for the moveNode event; when dragged to the root, args[1] is null, so to get the siblings I need to call Tree.getRoots() which is where the issue is, as this is the data and order is BEFORE the move, whereas args[1].children is the data and order AFTER the move.

As I am using the nested set model in my database (LFT & RGT), there is no way to determine the sibling the moved node is being inserted after.

As moveNode is called AFTER the drag and drop, Tree.getRoots() should be the order and data after the drop, just like args[1].children is.

jplevene

  • Pro Ultimate
  • Full Member
  • *
  • Posts: 131
    • View Profile
Re: Bug in moveNode event or Tree.getRoots() - FIX
« Reply #1 on: May 27, 2024, 09:34:27 pm »
The only way I managed to fix this was by doing a setTimeout.

Code: [Select]
moveNodes: function() {

   console.log($.extend({}, $("#tree").pqGrid("Tree").getRoots()) ); // <<<------------ OLD ORDER BEFORE THE MOVE

   setTimeout(function(){
       console.log($.extend({}, $("#tree").pqGrid("Tree").getRoots()) );   // <<<------------ DIFFERENT & CORRECT ORDER COMPARED TO ABOVE
   }, 1);
}
« Last Edit: May 27, 2024, 09:42:57 pm by jplevene »