35
Views
6
Comments
Solved
How to sort with multiple condition on one table
Application Type
Traditional Web

Hello everyone
I have a table that is display some data onto the screen, i have this field ImportDate that is record the date when the import were made, there are 2 possible data for this(null and an actual date). Now i want to display on the screen the import record with the null data first, then the ImportDate
Example: 1st jan 2025 i create 2 record with date, 2nd jan 2025 i create 2 record with date , 2nd jan 2025 i create 2 record without date, and in 2020 1st jan i already have 2 record without date, what i wanted is the following display
1. 2 record without date created in 2nd jan 2025
2. 2 record without date created in 1st jan 2020
3. 2 record with date created in 2nd jan 2025 
3. 2 record with date created in 1st jan 2025
When i try using the normal way of sort like ImportDate Desc, it sort the way i want that is the newest created record go to the top,but then the record without date always to to the bottom. Asc is for those null record to go to the top(also the way i want) but now newest created record with date is at the bottom
Can you guy help me?
*Note: i have 2 field ImportDate and CreatedDate too, createdate data is always added even when the ImportDate is created null, but sort is sorted by ImportDate
**Note: here is the code that is in the sort: List_SortColumn_GetOrderBy(ProductTable, "{product}.{ImportDate} Desc")
***Small update: the record without date can display however you want, doesn't care about the create time, but the one with date is a must

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

You can add an extra calculated column, 'IsNull', value 1 if importdate is empty, value 0 if it is filled.

Sort on 

IsNull desc

Importdate desc

Createddate desc 

 

UserImage.jpg
Long Truong Hoang

OMG it work, thank you very much!
But sorry to bother you one more time, now when i click the header of the column to sort, it doesn't work, like every other column too(Class name, class status,...), when i click on them nothing happen anymore, i tested with my other table(The same data) but haven't apply your solution yet and the sort when click it's still work
My table using some kind of widget to sort, RichWidgets\Lists_SortColumn, and in the column i have this "{product}.[ImportDate]" (the image is i borrow from the internet for example)

UserImage.jpg
Long Truong Hoang

Oh i figure it out the later questions
Once again, thank you so much
Regards
John

UserImage.jpg
Long Truong Hoang

Sorry for bother you once more, but i need your help
The display is already ok, but now when ever i try to click the header to sort, it will just sort back to the old sort by ImportDate, it doesn't go to the sort that i put in the aggerate
Example:
Here are the record that you have help me
1. 2 record without date created in 2nd jan 2025
2. 2 record without date created in 1st jan 2020
3. 2 record with date created in 2nd jan 2025 
4. 2 record with date created in 1st jan 2025 
AFter click the header to sort, it become like this
Click sort once
2. 2 record without date created in 1st jan 2020 
1. 2 record without date created in 2nd jan 20254
4. 2 record with date created in 1st jan 2025 
3. 2 record with date created in 2nd jan 2025  
Click sort again
3. 2 record with date created in 2nd jan 2025 
4. 2 record with date created in 1st jan 2025 
2. 2 record without date created in 1st jan 2020 
1. 2 record without date created in 2nd jan 2025
It basically just go back to the old way
*Here is my current sort in the aggerate
List_SortColumn_GetOrderBy(ProductTable.Id, "[IsNull] desc")
List_SortColumn_GetOrderBy(ProductTable.Id, "[ReportDateTime] desc") 
List_SortColumn_GetOrderBy(ProductTable.Id, "[CreateDateTime] desc") 
Regards
John

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

oke, wait a sec, I don't remember the exact mechanics of Traditional Web, I'll have a try

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

I don't have enough time to work it out, but if you want to have this special sorting and also want to allow the user to click headers for sorting, I would do something like

  • add local text attribute in your screen, called DynamicSort
  • use that in your aggregate as sort value instead of the normal ListSortColumn....

  • add 2 local text attributes named specialSortImportDateAscending and specialSortImportDateDescending, with default values filled

Let's say you want the sorting to start on this special order ascending, in your Preparation, right before the aggregate, you assign the DynamicSort like this

So now, in the Refresh is the most work : you have to set the DynamicSort value either directly as is selected in the header, OR one of the special sorts if they clicked on ImportDate

I split it up in 3 steps for easier readability

Dorine

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