1051
Views
8
Comments
Solved
How can I proper sort a list on an reactive app?
Question

Hello guys, I am trying to do a sort of a table on a Responsive Application and I am getting a weird behavior. It work for some columns and for other doesn't. In the column name it works just fine, but, for instance, on the account number it appears random. 

Can you help me? 

I leave here some screenshots of the code.



2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello Bruno,

Hope you're doing well.


That behavior happens when you have different Data Types associated to one single ListSort action.

If you have different Data Types in a single ListSort, they will be assumed as a single Data Type and this may lead into some undesired behaviors.


For example, assuming that your Name field is a Text and your Balance field is a Decimal, if these fields are both in the same ListSort, your sorting will be executed considering both of them as Texts.


In this scenario, you need to separate your fields in several ListSort actions (depending on their Data Types).

Based on your Sort attribute, you can place an If / Switch widget to evaluate your fields and have a ListSort for each Data Type.

I believe that decimals, currencies and integers can be placed in the same ListSort, but you can test it out.


In your case, it should be something like (I'm assuming your Data Types):

  • One ListSort action for field Name (Text);
  • Another ListSort action for fields AccountNumber (Integer) and Balance (Decimal);
  • Another ListSort action for field CreatedOn (Date).


Hope that this helps you!


Kind regards,

Rui Barradas

2021-03-05 13-56-11
Ricardo Pereira
 
MVP

Hi,


The AccountNumber attribute type, is Text or Number? Because, if it's Text, you can have a sorting based in the characters codes and not in the number sequence.


Best regards,

Ricardo M Pereira

2020-05-07 18-53-00
Rui Barradas
 
MVP
Solution

Hello Bruno,

Hope you're doing well.


That behavior happens when you have different Data Types associated to one single ListSort action.

If you have different Data Types in a single ListSort, they will be assumed as a single Data Type and this may lead into some undesired behaviors.


For example, assuming that your Name field is a Text and your Balance field is a Decimal, if these fields are both in the same ListSort, your sorting will be executed considering both of them as Texts.


In this scenario, you need to separate your fields in several ListSort actions (depending on their Data Types).

Based on your Sort attribute, you can place an If / Switch widget to evaluate your fields and have a ListSort for each Data Type.

I believe that decimals, currencies and integers can be placed in the same ListSort, but you can test it out.


In your case, it should be something like (I'm assuming your Data Types):

  • One ListSort action for field Name (Text);
  • Another ListSort action for fields AccountNumber (Integer) and Balance (Decimal);
  • Another ListSort action for field CreatedOn (Date).


Hope that this helps you!


Kind regards,

Rui Barradas

2021-11-09 21-40-43
Fábio Godinho

I know the question is marked as solved, but there's an easier way no to worry about the different data types of the sort attributes (if they are text, date, integer, identifiers..) and having lot's of List Sorts.


On the Sort By of the List Sort action, have all the if's returning ToObject() of their attributes.

And always remember to handle the descendant/ascendant behavior.


Hope this helps!

2025-12-29 06-17-15
Deepak Raj M

Hi All, I know this is very old, but i need this , can one can share oml of this .

2023-10-16 05-50-48
Shingo Lam

I think @Fábio Godinho shared the screenshot, its enough to implement the sort

In case, there are a lot of fields to consider, I usually choose JavaScript to dynamically sort. Please check my attached JavaScript file, then just pass the list as text (JSON serialized) to the JavaScript node along with sort column name and order

Example usage:

const listItems = [

  { name: "Banana", price: 10 },

  { name: "Apple", price: 5 },

  { name: "Mango", price: 7 },

  { name: "Orange", price: 8 }

];


// Sort by name in ascending order

listItems.sort(dynamicSort('name', 'asc'));

console.log(listItems);


// Sort by price in descending order

listItems.sort(dynamicSort('price', 'desc'));

console.log(listItems);


dynamicSort.txt
2023-10-16 05-50-48
Shingo Lam

Please refer to my attached oml for both local list sort

SandboxReactive.oml
2019-03-19 12-24-07
Mariano Picco
 
MVP

I'm trying to use this method but I'm getting a 'Generic Type' data type required instead of 'Object' error. It's incredible how difficult it is to solve this very basic issue.

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