Closed 1998MaxChykalo closed 1 year ago
Any update on this? I am facing same issue.
nvm, I can access parent and previous node with setup easy. All good for me.
@minop1205 any update? same issue
Is there any update or any workaround for this, I need to know the index of an item where it inserted with respect to its parent in case of sortable false. @minop1205
Please update ASAP.
is there anyway to add id to the li element? @minop1205
Sorry everyone for misleading you with the README explanation. First, let us discuss destinationIndex.
If the sort
property of the tree is false
, the order of the nodes follows the order of the data array.Therefore, reordering the nodes requires reordering the data array.
destinationIndex
is not an index value relative to the parent node, but rather an index value indicating where in the data array the drag source data is to be moved.
In fact, the array swapping is done inside the library, and the onDrop
callback receives the reordered data array.
There is currently no way to get the index value relative to the parent node. I will make it available in the next update.
Also, I'll correct the description of destinationIndex in the README.
If you don't mind me asking as a reference, what is the use of relative indexes? For example, is this a case of sending a relative index to synchronize the tree sequence with the server?
Sorry everyone for misleading you with the README explanation. First, let us discuss destinationIndex.
If the
sort
property of the tree isfalse
, the order of the nodes follows the order of the data array.Therefore, reordering the nodes requires reordering the data array.
destinationIndex
is not an index value relative to the parent node, but rather an index value indicating where in the data array the drag source data is to be moved.In fact, the array swapping is done inside the library, and the
onDrop
callback receives the reordered data array.There is currently no way to get the index value relative to the parent node. I will make it available in the next update.
Also, I'll correct the description of destinationIndex in the README.
If you don't mind me asking as a reference, what is the use of relative indexes? For example, is this a case of sending a relative index to synchronize the tree sequence with the server?
@minop1205 in my case, i wanna to update order in database after reordering items. Cuz destinationIndex is wrong, i'm calculating order in current lvl, by checking position in array. Ordering is applied in some lvl For example: 1 Parent1 1 Child1 2 Child2 2 Parent2 3 Parent3 1 Child1 2 Child2
@minop1205 Yes, I need to synchronize the tree sequence with the server. Otherwise how will we know where the node is inserted when we are reordering within the same parent or different parent.
Anyway for those who are still stuck in this issue, I have found a workaround or hack you can say.
Here is the code for the same, You already have the drag node id and you can get the parent node of the same
Basically need to pass down the node and parent node to the list item and get all the items from the dom.
@hightgha @a-utkarsh Thank you for your comment!
I have just released v3.3. In this version, an option called relativeIndex is available in addition to destinationIndex.
The relativeIndex indicates the index relative to the parent node. The relativeIndex is actually equivalent to the index of the placeholder.
Below is an image of how it works.
I will Close this Issue, but reopen it if you have any problems.
if I drag an element and drop it at the root level then
destinationIndex
is calculated as if every element is the direct child of the root element. Example:the
destinationIndex
is 6. But we have only 5 elements in the root, so thedestinationIndex
in this case should've been 4:If we drop an element to some nested item, then
destinationIndex
is calculated relatively to the item it was dropped on. link to sandbox: https://codesandbox.io/s/minimum-configuration-js-forked-n3yor6?file=/src/App.jsxExpected result:
destinationIndex
is calculated based on the level of nesting where it was dropped