List Sort Action with condition

Hi Team,

I have a list of records and I want to sort them in a way where I can show first those with "status" = "pending" before the other with "status" <> "pending"

Is there a possible way to do that with List Sort or Is there other option?




Rank: #19

Hi Nhorwin,

The simplest way is to add a calculated attribute to your Aggregate, where the formula is: If(MyEntity.Status = Entities.MyStatus.Pending, 0, 1), and then add a (static) Ascending Sort on that calculated attribute.

If you place it before your dynamic sorting (that uses the List_SortColumn) it will first split your records into pending/not pending and then sort inside those two categories according to your dynamic sort, if you place it afterwards, you sort by your criteria and only afterwards apply the separation between pending/not pending.

You can also use the name of the new calculated attribute directly on a List_SortColumn's Column to sort by it, either showing first the pending ones or the not-pending ones.

Thanks Jorge,

Will try to do so. But can it also be done using ListSort Action, due to that I hold the list on a variable not on an entity?

As of now, I am using 2 list filters with conditions "status" = "pending" and "status" <> "pending" respectively. Then AppendAll to the variable

Rank: #19

Hi Nhorwin,

The way List_SortColumn behaves is by storing in a (unaccessible) session variable a string representing the ORDER BY criteria, using the syntax "{Entity}.[Attribute]" or "CalculatedAttribute". Depending wether you click on the header once or twice it will either append or not the strings " ASC" (or was it " DESC"?) to the end of the column string (to change the sorting direction).

I don't understand exactly what list are you storing on your variable. If you want to dynamically decide to show first the pending ones or the non-pending ones, you can use List_SortColumn with the column set to "CalculatedAttribute": when you click on the header that has that List_SortColumn it will either show first the pending records, or the non-pending records.