grist-core
grist-core copied to clipboard
Bug: sort by date column with empty values last
The "empty values last" setting doesn't appear to make a difference in the sort right now (at least in a date column).
https://user-images.githubusercontent.com/8421688/234416122-1302a452-1917-4a60-92e6-5cac4b3f65db.mp4
I noticed this when I was trying to sort the rows such that empty dates are first and then ascending dates.
This is how I'd like the sort to work in my example, but I couldn't figure out a configuration that worked:
| Name | Due Date | Done |
|---|---|---|
| Test 4 | false | |
| Test 5 | false | |
| Test 2 | 2023-03-20 | true |
| Test 1 | 2023-04-25 | false |
| Test 3 | 2023-04-28 | false |
I would expect that when "empty values last" is not selected, that means empty values are first. But I could not figure out how to get the empty values first with dates in ascending order.
Has anyone been able to at least confirm that they're seeing the same thing I am?
I can confirm that there is a Fix handling of empty values when sorting Date columns in our backlog, I believe there is a genuine bug here.
I can confirm that there is a
Fix handling of empty values when sorting Date columnsin our backlog, I believe there is a genuine bug here.
Having the same problem. The problematic empty comparator seems to be defined in the following file.
app/common/SortFunc.ts: 38-53
/**
* Empty comparator will treat empty values as last.
*/
export const emptyCompare = (next: Comparator) => (val1: any, val2: any) => {
const isEmptyValue1 = !val1 && typeof val1 !== 'number';
const isEmptyValue2 = !val2 && typeof val2 !== 'number';
// If both values are empty values, rely on next to compare.
if (isEmptyValue1 && !isEmptyValue2) {
return 1;
}
if (isEmptyValue2 && !isEmptyValue1) {
return -1;
}
return next(val1, val2);
};