130
Views
10
Comments
Solved
Sort Table
Question

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

2020-11-10 07-09-26
Dadi
Solution

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.

SortText.oml
2024-12-16 09-23-37
Toan Dinh

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.


2023-11-22 10-51-50
Jozy Sohail

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

2023-02-09 12-36-42
Damian Fonville

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

2020-11-10 07-09-26
Dadi

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

UserImage.jpg
Tom Smith


I create the numbers here, how can I add prefix zeros to the numbers?


many thanks


UserImage.jpg
Tom Smith

is this for the ListSort ?

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") 


many thanks

2020-11-10 07-09-26
Dadi

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

2023-10-27 15-22-44
Rahul Yadav

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

2025-06-01 02-51-51
YASH PAL

@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.

2020-11-10 07-09-26
Dadi
Solution

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.

SortText.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.