Read to object with merge resets sorting

Hi!

I have a function that recursively navigates from a target and up the “tree” towards root, to make sure a folder structure is expanded, and that breadcrumbs are set up correctly.
But the breadcrumbs are sorted the wrong way, I use a “Sort objects in” node to invert the list like this:

image

As you can see, I sort the objects first, then add the selected/target node to the end to make it appear in the breadcrumb.
The sorting works if i don`t add the last element, and when I do add the last element, it gets reset to the order the objects was added into.
Is this a bug or am I misunderstanding how this should work?

Hi, Marcus

If i understand your use-case correctly, you want to read an object to the end of your inverted list of folders, that is also displayed in your app?

I have recreated your setup and got the same result as you did. To solve the issue of the sorting “resetting” when reading/merging in an object, i added a runtime property of type integer named “Runtime Index”. I sort the iteration of the data source in the UI using this new property.

I set the value of this property using a function taking the object count of the runtime data source and subtracting the objects Index in data source as well as 1. In the UI, I sort the runtime objects by the “Runtime Index” in ascending order. When I then read an object into the data source and assign it “Runtime index” = “Index in data source”, the table keeps its sorting and the new object is added to the end. If you wanted to store this in the database to keep your folder hierarchy, you could add a new property on the object class called “Folder Index” or something similar.

In our docs, we recommend defining separate properties for sorting rather than using the “Index in data source”. I hope this helps, let me know if this does not apply to your use-case :slight_smile:

Nikoline

Hi @Nikoline!

Since I am setting _m_DR_Node (temp) into a value on a runtime property, I ended up just merging the array and the last element in a function that sets the value, like this:

return [...mDRNodeTemp.map(n => n._id), currentNodeId];

I am still wondering if the array order reset is intended behaviour or a bug tho :thinking:

My initial thought was that it would function a bit like this:

const myArray = ["c", "b", "a"];
myArray.sort(); // Changes to ["a", "b", "c"]
myArray.push("d");
console.log(myArray); // Array(4) [ "a", "b", "c", "d" ]

But I might have been mistaken :sweat_smile:

Marcus

Hello again,

Good thing you found a solution! We discussed this internally, and for now I will register this as a challenge, and our devs team will take a look at improving this issue. I cannot tell if this is a bug or not, but I agree in that this is odd/unexpected behaviour.

Thank you for pointing it out.
Hopefully an improvement is on the way :+1:

Nikoline