Sorting Groups Ascending or Descending

I am grouping and sorting a table by date, no problems. When looking at the table, we want to know which day it is; no problem there, we can:
concat(date," ",date.weekdayname()) = ‘1/1/2020 Monday’

However with the text now added to the field, we sorting no longer works. Any ideas on how to preserve the group sorting while doing something like this?

Hi @Johg_Ananda,
my suggestion seems so obvious that I have the feeling I’m missing something:

What about keeping both fields (date and transformed date); the first one for sorting the second one for displaying purposes?

In your specific case I’d say play around with the hidden .FormatDateTime() instead.

It will let you show weekday along the date (although weekday will probably go before the date, not after), but unlike Concatenate, this will NOT change value type from Date to Text. So, sorting should still work properly on values as if they were dates, not text.

If you absolutely need weekday in the end, then I suggest making it a separate column and showing to the right of your grouped one. Perhaps group on it as well so that you see it only once per group.

@Federico_Stefanato yes, you’re missing the fact that ordering of groups takes precedence over sorting on any other column. Even if you disable sorting on your date group, their last relative order would still remain “pinned” in the system. I reported this a while ago, but it’s not fixed, and I’m afraid it’s not that trivial to fix either. TL;DR: Coda remembers ordering of groups, and no sorting on ungrouped columns will affect it. It will affect the order of rows within each group, but not of the groups themselves.

1 Like

Hi @Paul_Danyliuk I had this suspect, especially considering @Johg_Ananda skills: thanks for the explanation

1 Like

Also a much easier way — instead of .FormatDateTime() just change column format settings via UI to show weekday :slight_smile:

1 Like

Ah this would have been such a simple and sweet solution, alas! it does not work:

This does work … only if the column is a text format, not a date format, which is a bit counterintuitive. By mirroring the column with the .formatdatetime() and changing to text, the group sort did work:
Screen Shot 2020-07-08 at 1.42.43 PM
:pray: @Paul_Danyliuk

1 Like

Regarding the “simple and sweet solution” — can you try it once again, but first ungroup and then group again? Sometimes Coda doesn’t regroup after column settings changes.

Text column type works because Text is “any type” kind of column, it just outputs values at face value and doesn’t try to convert them to anything. Date type doesn’t work because date column format settings override your formula output.

I don’t know if this helps…but I found that if I make it a text column and then make an interactive filter, you can type in specific dates to filter them. If you use a macro program like Keyboard Maestro, you could then create keyboard shortcuts for Today+1, Today-1 etc.

1 Like

I also discovered (maybe everyone else knew this already??? :wink: that since you can group multiple fields, if you sort by the field you want and then make it your first group, it will give you the sort you want in the grouped view. I actually found that the best way to do this is to make a new column and copy the values of the column you want there (thisrow.[sort_column_name], and use that new copied column for your sort and first group.

I hope that is helpful for someone…I am grateful for all the help I get here, and I am trying to contribute in the best (although non-technical) way I can!

Gregg

2 Likes

There’s also a way to hack the sorting of groups themselves, no extra group column needed. I wanted to re-record the video and publish it as a separate topic but didn’t have time for that yet.

(the hack starts at about 13:55)

3 Likes

Lucky 13!
Does it matter if the list has hundreds of items?
Gregg

Well, at some point you’ll have a label that starts with 100 character 13s :slight_smile:

It marginally adds to doc size, but given all else it’s negligible (6 bytes per character, because the doc is a JSON and CR is encoded as \u000D there)

The only risk is that eventually Coda may crash (spin into eternal Calculating) on that character 13 (CR) as well. It’s less likely to happen than other characters because e.g. Windows still uses the “CRLF” (Character 13, Character 10) sequence for a newline, and Coda probably just ignores the CR silently so that copy-pasting things from Windows text editors (Notepad etc) keep working.

P.S. If you’re expecting to have 100s of groups, that could be a bigger issue on itself. Grouping is slow, and the more groups there are, the slower the page will be in general (there’s calculation overhead and also UI drawing overhead). You probably want to avoid that altogether.

1 Like

Thank you @Paul_Danyliuk - I have been frustrated with group sorting for so long and this, and this hack does mitigate it for the most part (though Coda really should fix this!)…So many gems of yours hidden in this forum!

1 Like