Bug: When sorting by Mixed String (Text & Value combination)

I have a list of apartments -

When sorting the inline list by a Text column with numbers;
B1001 (10th floor) will be before B301 (3rd Floor) -

it shouldn’t be like that.

When you convert a number into text, it will sort as text. To properly sort text that contains numbers, you have to left pad the number with zeros. What I would do is first convert the number into a decimal by dividing by 1000. So 1001 becomes 0.1001 and 301 becomes 0.0301. Then join that value to with your letter and sort by that value.

So you’re saying it should Say Apt B.1001 and B.0301?

Right!

To have a better sorting by using alphanumeric codes, the first step is to have a code with the same length for any case. I mean, with the same format:

B0101, B0102, B0103, B0201, B0202, B0203 …

…B0901, B0902, B0903, B1001, B1002, B1003, etc

I hope it helps.
Saludos!

2 Likes

An alternative would be to have a separate (number) column that contains only the numeric part of the apartment number (1001, 301, etc). You could then use that column for sorting the list.

Depending on the significance of the “B”, and how it is determined, I’d probably store them as numbers anyway, and then prepend the “B” just for display, either with a template or as a “units” indicator - whichever made more sense.

2 Likes

Closing due to inactivity. This topic will be deleted in a few weeks if there are no more comments.