Tasks plugin: how to sort groups? #2723
-
What I'm trying to doI would like to sort groups based on the I have this code: ```tasks
filter by function task.file.folder.includes('Work') || task.file.folder.includes('Daily notes')
filter by function task.status.symbol == ' '
group by folder
group by function '%%' + task.happens.format("YYYY-MM-DD") + '%%'
group by filename
``` Here is an output. Sorry for the sanitization: As you can see, the note What I want, is the group by function '%%' + task.happens.format("YYYY-MM-DD") + '%%' ... only return the minimum date from all the dates in the Things I have triedThe code bellow. And a bunch of alternatives. Non worked. Maybe something like: sort by function Math.min(task.happens) ... but does not work. Any ideas? I am using:
Cross post with https://forum.obsidian.md/t/tasks-plugin-how-to-sort-groups/78961/1 |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
No task text, so we cannot experimentThere's a lot going on there, and you haven't given me any task lines as text that I can copy and paste in to a vault to experiment with. So I'm limited in what I can usefully say. However, it is useful to have the query as text - thank you. Invisible headingsI am confused as to the purpose of this line:
It produces a heading whose text is entirely commented out and invisible, but the text still differs if the Try changing that text to this and you will likely see what's going on:
I suspect that what appears to be the duplicate What you wantUnfortunately I do not understand what the following is requesting, in particular the last line:
Cross-posting
Oh - had there been a reply there already, I would have wasted the time above. If you're going to cross-post, it would be appreciated if you could put the cross-post like at the top in both locations. |
Beta Was this translation helpful? Give feedback.
-
Thank you @claremcrae for your response.
Let's consider these example notes:
- [ ] Task 1
- [ ] Task 2🛫 2024-03-22
- [ ] Task 3
- [ ] Task 4
- [ ] Task 5
- [ ] Task 6 🛫 2024-03-22 And the following summary note: ```tasks
filter by function task.status.symbol == ' '
group by folder
group by function '%%' + task.happens.format("YYYY-MM-DD") + '%%'
group by filename
```
```tasks
filter by function task.status.symbol == ' '
group by folder
group by filename
group by function task.happens.format("YYYY-MM-DD")
``` For the chuck of code at the bottom (with no So, as you can notice, for the file But, what I want, is to:
Is this possible? |
Beta Was this translation helpful? Give feedback.
-
You might want to have a look at this section of the documentation: https://publish.obsidian.md/tasks/Queries/Grouping#Notes If you want to sort the tasks within a group, add a |
Beta Was this translation helpful? Give feedback.
-
Thank you @claremacrae for your response. After your comment on This is my final code: filter by function task.file.root == 'Work/' || task.file.root == 'Daily notes/'
filter by function task.status.symbol == ' '
group by folder
group by function \
const date = task.happens.moment; \
const now = moment(); \
const max_diff = 1e6; \
const label = (order, diff, name) => `##### %%${order} ${max_diff + diff}%% ${name}`; \
if (!date) return label(4, 0, 'Undated'); \
if (!date.isValid()) return label(0, 0, 'Invalid date'); \
const date_diff = date.diff(now, 'days'); \
if (date.isBefore(now, 'day')) return label(1, date_diff, '< ' + Math.abs(date_diff) + ' days ago'); \
if (date.isSame(now, 'day')) return label(2, 0, '= Today'); \
if (date.isAfter(now, 'day')) return label(3, date_diff, '> In ' + Math.abs(date_diff + 1) + ' days'); \
return label(4, max_diff, 'Other');
group by filename
# explain The result looks like: Thanks! |
Beta Was this translation helpful? Give feedback.
Thanks for the extra info.
Sadly I have no idea what
the minimum task.happens inside the file
is?Nor this:
In case it helps, Grouping and Sorting all work on the data in each individual task line. They do not take account other information in other tasks inside a group or a file.