Does ListSort sort Integers as Text?

Does ListSort sort Integers as Text?

  

Hi,


So here I am with my TableRecords component which is filled with multiple items retrieved from REST services. ListSort component works pretty good except decimal which seem to be sorted as Text values so if I have:


12

222

140

5000

3333333


It would be sorted (ascending) as:


12

140

222

3333333

5000


Instead of the proper (ascending) order for integers that should be:


12

140

222

5000

333333



What is going on with ListSort component?


Jordi.


Hi Jordi,

ListSort component uses the generic data type and it is based on the Datatype of the selected attribute in the list,

if you are passing a list and selecting a text attribute to sort, it will function as the text datatype.

Thanks

Kirit

kirit kumar wrote:

Hi Jordi,

ListSort component uses the generic data type and it is based on the Datatype of the selected attribute in the list,

if you are passing a list and selecting a text attribute to sort, it will function as the text datatype.

Thanks

Kirit


Hi Kirit,


I'm not trying to be rude or anything but have you read my post at all? ListSort is working as intended on every single field but the Integer one,as I said before, Integer (numbers) values are sorted like if they were plain text instead of actual numbers.


Check the example shown before to help understand what I'm getting on my OS project.


Jordi.

Hello Jordi


I think what Kirit was saying is that if the attribute is defined as text, if will be sorted as text.

You have two options to fix this

1) change the attribute's data type to integer

2) call the texttointeger() built in function on the list sort


Let me know if you have anymore questions

Regards,

Ângelo

Ângelo Sousa wrote:

Hello Jordi


I think what Kirit was saying is that if the attribute is defined as text, if will be sorted as text.

You have two options to fix this

1) change the attribute's data type to integer

2) call the texttointeger() built in function on the list sort


Let me know if you have anymore questions

Regards,

Ângelo


Hi Ângelo,


I hope you can see it clearer with these screenshots:



Jordi.

Hi Jordi,

Can you tell the datatype of attribute TotalRecibo? 

which is the key to your question!

Hi Jordi,

Just to be sure, when you are talking about the ListSort "component", you mean the ListSort System Action right?

A few things I don't understand:

  1. You talk about Integers not being sorted right, but your example above shows a Decimal.
  2. You're doing a TextToDecimal, but the attribute is already a Decimal?
  3. The output shows a formatted Decimal, I assume that's not the thing that gets sorted (but instead the Decimal itself)?

That said, I tested the sorting in a simple test program, and it works fine (i.e., as expected), so there must be something to your code that's causing this behaviour.


kirit kumar wrote:

Hi Jordi,

Can you tell the datatype of attribute TotalRecibo? 

which is the key to your question!


Hi Kirit,


You can check it by yourself:


From its entity/database (mocked data to rely my main project on a REST Service ):




Received data from REST Service:



Structure attribute received from REST Service:






As you can see, it's a decimal and yes, on the ListSort I've set TextToDecimal() and it's still working as if any decimal value was a test one instead.


Jordi.

Jordi,

You provide too little info to get to the root cause of your problem, _and_ you're doing questionable (or at least superfluous) things like setting a TextToDecimal on an Attribute that's already a Decimal. Unless you provide some more details, there's little we can do to help you. ListSort works fine, so if it doesn't, there must be a bug in your code.

Kilian Hekhuis wrote:

Hi Jordi,

Just to be sure, when you are talking about the ListSort "component", you mean the ListSort System Action right?

A few things I don't understand:

  1. You talk about Integers not being sorted right, but your example above shows a Decimal.
  2. You're doing a TextToDecimal, but the attribute is already a Decimal?
  3. The output shows a formatted Decimal, I assume that's not the thing that gets sorted (but instead the Decimal itself)?

That said, I tested the sorting in a simple test program, and it works fine (i.e., as expected), so there must be something to your code that's causing this behaviour.



Hi Kilian,


That is correct, I'm using System's ListSort Server Action.

1.- Well, yeah, you're right,on the title I talk about Integers while I'm having problem with decimals. Sorry about that, let me edit the OP and it's title

2.- Yeah, at first I didn't format it to Decimal but as someone suggested, I put that function in just in case "forcing" it will work but it didn't.

3.- That formatted output comes from an expression used on the TableRecords :

SyntaxEditor Code Snippet

FormatCurrency( RecibosTable.List.Current.TotalRecibo, "", 2, ",", "." )+"€"



If you don't mind, try testing it again with the format above just in case it is breaking the sorting somehow.


Thank you,

Jordi.

Kilian Hekhuis wrote:

Jordi,

You provide too little info to get to the root cause of your problem, _and_ you're doing questionable (or at least superfluous) things like setting a TextToDecimal on an Attribute that's already a Decimal. Unless you provide some more details, there's little we can do to help you. ListSort works fine, so if it doesn't, there must be a bug in your code.

What about this?



If it is not clear enough, I'm trying to sort my TableRecords component by all the fields shown on the table itself by using List_SortColumn widgets.


Jordi.

Kilian Hekhuis wrote:

Jordi,

You provide too little info to get to the root cause of your problem, _and_ you're doing questionable (or at least superfluous) things like setting a TextToDecimal on an Attribute that's already a Decimal. Unless you provide some more details, there's little we can do to help you. ListSort works fine, so if it doesn't, there must be a bug in your code.

Hi Kilian,


Do you need any extra information ?


Jordi.


Solution

Hi Jordi,

I see now what your problem is. The ListSort sorts by whatever type you specify as the "By" parameter. However, an If also returns a single data type, and since there is Text in your Ifs, _all_ output will be Text. You need a ListSort for each Data Type (or for each column). I think the easiest way is to implement it with a Switch.

Solution

Kilian Hekhuis wrote:

Hi Jordi,

I see now what your problem is. The ListSort sorts by whatever type you specify as the "By" parameter. However, an If also returns a single data type, and since there is Text in your Ifs, _all_ output will be Text. You need a ListSort for each Data Type (or for each column). I think the easiest way is to implement it with a Switch.

Hi Kilian,


Thank you so much, now it works as intended! Sorry for not showing all the information needed to find the root of the issu.


Jordi.


Hi Jordi,

No problem, you couldn't have know what information to supply, I'm glad we found out eventually. Happy coding :)

I know this has already been marked as solved, but I wanted to add a solution I found that works also.  

In your ListSort "By" parameter, you can use ToObject() for all your fields and it should sort everything correctly.  So the "By" value would look something like - 

If ( Session.ListSort = "TipoContrato", ToObject(TipoContrato), 

     If (Session.ListSort = "Producto", ToObject(Producto), ToObject(NoContrato))

)