Hello everyone,
I have the following question:
I am sorting a list by number, but it is not sorted correctly in the display.
It works up to 10 from 11 the 11, 12, 13.. jumps back below the 1.
Table Source is:
I use ListSort in for the Action:
Many thanks in advance
Hi @Tom Smith
its not best practices, but here is some example that you can use for your requirements:
1. Sort by SQL - you need sort length of text then sort the values
2. Sort by function - create loop function to make temporary values for sorting table
you can try and find what suits for you.
Hi, Tom Smith
Because data type of Number is Text, so it will sort one by one. It means: T1 -> T11 -> T111 -> T2
If you want sort by numberic part, you should convert numberic part to integer, then sort by this.
Hi Tom,
As Manh said it is a text value so it is sorting in this way.
You can use some other element in your list which is of type integer and has a sequence same as your text element.
Hope it helps.
Thanks
A solution is to add prefix zeros to the numbers, You can use https://success.outsystems.com/documentation/11/reference/outsystems_language/logic/built_in_functions/format/#FormatText
2023-IAQ-001
2023-IAQ-002
2023-IAQ-003
.....
2023-IAQ-010
2023-IAQ-011
I found that @Damian Fonville was accurate.
Its better use prefix rather than convert text to integer, because it still have sort the 2023-IAQ-... that can be anything.
Then we need split the text by "-" to set prefix in last items. Use this value to sort for example:
String_Split("2023-IAQ-1", "-")[0].Text.Value + "-" +String_Split("2023-IAQ-1", "-")[1].Text.Value + "-" +FormatText(String_Split("2023-IAQ-1", "-")[2].Text.Value, 4, 4, True, "0")
use minimum and maximum 5 if the value is more than thousand
I create the numbers here, how can I add prefix zeros to the numbers?
many thanks
is this for the ListSort ?
lets say in customAudits there is Number column, so add new attributes for example NewNumber and do for looping to put expression in each rows
change "2023-IAQ-1" with current Number, i believe it would be like this:
String_Split(customAudits.list.current.Number, "-")[0].Text.Value + "-" +String_Split(customAudits.list.current.Number, "-")[1].Text.Value + "-" +FormatText(String_Split(customAudits.list.current.Number, "-")[2].Text.Value, 4, 4, True, "0")
then sort the list by NewNumber column
Hi @Tom Smith,
As already stated by the other members, since this is a text value it wouldn't've sorted typically in your case.
You can try @Dadi's proposed solution if the record set is not huge.
Can I ask you if you are getting the data from an aggregate or is it an external service and how much data is expected in the record set?
Thanks,
Rahul Yadav
@Tom Smith
I have encountered the same situation and solved with the following steps.
1. Created another attribute in the List.
2. Assigned only the Numeric part of that Text value but extracting using the Substring() function.
3. On the table sort instead passing the Text variable passed the integer variable.
4. applied sorting using the integer variable.
I hope this might help you.
Thanks.