Sort... not sorting the way i'd like

Hey all,
im looking to sort those views using the name. Any idea why it doesnt seem to use the entire string to sort?

As the items are strings, it compares the characters one by one. The result is actually ok, considering the 9th character of all strings is sorted properly (1, 1, 1, 7, 8).

You can try to rename your sections to always have 2 digits (00, 01, 02…09) or try something like below

This is just a sample file this is not how we usually name our sections but it shines some light on the way it works :slight_smile:

I guess tha as long as any numeric value on the name has always the same number of digits (00, 000, etc), it should work fine :slight_smile:

Instead of a sort by function try getting the name values and use some string manipulation instead. This will allow you to drop those characters or otherwise alter the data to fit your needs.

@alvpickmans I’m a big fan of the Pad Left…

yeah that works too! :slight_smile:

I would only be concerned on large sets. Not an expert but I assume that comparing "001" and "002" (strings) will take 3 comparisons (first characters, then seconds and finally 1 and 2), whereas comparing numerical values is straight forward.

Not sure either how expensive would be to convert from string to number though :sweat_smile:

I have two sorting nodes, one for “normal” sorting and one for sorting in natural order… take a look at those nodes in the orchid package.

@Daniel_Hurtubise as you can see from the below image, do the natural sorting node sort according to the names for the elements, while the normal sort don’t! the normal sort node is using the standard sort mechanism like the OOTB node does. However, both my nodes support nD list level since they are coded recursively.

2 Likes