1776
Views
6
Comments
Solved
Dynamic sort
Application Type
Reactive

I am new to Outsystems and exploring sorting tables in depth for the first time so I apologize in advance for the question, but I have read the documentation and can't quite figure out how to do it.

I will make a simple example:

I have a list of products (let's call the entity "Products") and two columns which I want to base my sort on:

Column A is "ExpiryDate" and columns B is "BoughtDate".

I want to display my products that I bought from most recent to oldest. So it would Products.BoughtDate DESC

I would like to show at the top only the products that have an expiry date expired (so < currDateTime()) and then the rest of the products with the Product.BoughtDate DESC

I am trying with the dynamic sort but I can't get to work.

I create a local variable, I initialize with the expression 

If(GetProducts.List.Current.Products.ExpiryDate < CurrDateTime,"Products.ExpiryDate","Products.BoughtDate DESC"

Am I overcomplicating things?

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Andrea Caselli ,

this is not related to dynamic sort, you just want to split your data into categories (expired vs not expired) and further sort within those categories.  

That can be done with normal sorting or dynamic sorting inside an aggregate, but you will need to create a calculated column to produce your 2 categories, and then you can add that in your sorting.

I made an example oml that happens to be using dynamic sort, but this could just as well be done with normal sort.  The key is making that category as calculated column, and putting that as first item in your sorting.

Dorine

QDR_SortingTwoDates.oml
UserImage.jpg
Andrea Caselli

Hi @Dorine Boudry ,

This is exactly what I needed! In the end, I have decided to do it by using the two calculated columns and a normal sort.

Thank you so much!

Andrea

UserImage.jpg
vikas sharma
Champion

Hi,

I think you can do one workaround, first first the records which have expired then others and sort them. Append both results in a single list. Although its not good idea to do but will work.

regards 

UserImage.jpg
Andrea Caselli

Hi @Vikas Sharma ,

Thank you for the suggestion. I am sure that this would work but I am a bit worried about using a workaround and I would have hoped that I could do something like this in Outsystems without using workarounds.

UserImage.jpg
vikas sharma
Champion

Yes, you are right. Its not a good work around.

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @Andrea Caselli ,

this is not related to dynamic sort, you just want to split your data into categories (expired vs not expired) and further sort within those categories.  

That can be done with normal sorting or dynamic sorting inside an aggregate, but you will need to create a calculated column to produce your 2 categories, and then you can add that in your sorting.

I made an example oml that happens to be using dynamic sort, but this could just as well be done with normal sort.  The key is making that category as calculated column, and putting that as first item in your sorting.

Dorine

QDR_SortingTwoDates.oml
UserImage.jpg
Andrea Caselli

Hi @Dorine Boudry ,

This is exactly what I needed! In the end, I have decided to do it by using the two calculated columns and a normal sort.

Thank you so much!

Andrea

2020-09-15 13-07-23
Kilian Hekhuis
 
MVP

Hi Andrea,

The easiest way may be to add a calculated column to the Aggregate that determines whether the product is expired, and first sort on that one, before sorting on the other. Also, I'm not sure why you'd need a dynamic sort for that, seems like you could do with an ordinary sort.

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