list sorting issue

list sorting issue

  

Hi everyone.

I am facing some issue with ListSort.
I have a some list records displayed on Ui with some column headers. I am sorting this list on click of column headers, everything is working fine when there are different values in list to be sorted.
But issue comes when i have all the records of same date (say) and i click on the column header for date, it sorts the list randomly.
What am I missing? Can someone please help.


Thanks,
Anagha


Solution

Hi Anagha,

I'm not sure what behaviour you expect. ListSort only works on a single Attribute of the List to sort. If there are duplicate values in that Attribute, it is still sorted, but the order of the elements with the duplicate values is undefined. Unfortuntaly, it is not possible to sort on multiple columns (I wish it was), so you can't easily solve this*.

*Of course, there's always workarounds, like creating one or more hidden Attributes that are composites of others, but depending on the size of the list, this could give some performance problems.

Edit: see this Idea. Also, there's a Forge Component that allows for sorting on multiple Attributes, but it is less user-friendly then the built-in ListSort.

Solution

Kilian Hekhuis wrote:

Hi Anagha,

I'm not sure what behaviour you expect. ListSort only works on a single Attribute of the List to sort. If there are duplicate values in that Attribute, it is still sorted, but the order of the elements with the duplicate values is undefined. Unfortuntaly, it is not possible to sort on multiple columns (I wish it was), so you can't easily solve this*.

*Of course, there's always workarounds, like creating one or more hidden Attributes that are composites of others, but depending on the size of the list, this could give some performance problems.

Edit: see this Idea. Also, there's a Forge Component that allows for sorting on multiple Attributes, but it is less user-friendly then the built-in ListSort.


Thanks for responding Kilian.

But my issue is a bit different.

These are my column headers, I am able to sort the list on single column (that is what my expected behavior is)
Everything is working fine when i have different hospital numbers, and other attributes.
Issue is when I have all records with same hospital numbers and I still click on the header, it sorts the list on something random. 

Hi Anagha,

Your issue is not different, your issue is exactly as I told you it is. When you click the header, it's going to sort the list. If you sort on a column that doesn't have all unique values, the result is undefined as to where the records end up. That's inherent to sorting.

Thanks Kilian,

But this should not be the case, right? If there are no unique elements the list should technically not sort at all.
Just a thought.

Anagha

Hi Anagha,

That depends totally on the sorting algorithm used. Ideally you may think it wouldn't change the order of elements, but many sorting algorithms may move the elements anyway. If a sorting algorithm doesn't change the order of record with identical keys, it is said to be "stable" (see e.g. here). Obviously, the algorithm OutSystems is using is not stable.