How to group tasks by File and then by Section? #720
-
I've been using this a lot, to ask dataview to get all the tasks from a set of files:
But I would like to extend this to group the tasks by section heading... So something like this:
I know that tasks now contain sections, but I cannot for the life of me work out how to use two levels of groupings. Any suggestions please? Edit - 2023-08-13 The two answers that produce two levels of groups (filename, then heading), using purely dataview/dataviewjs are: |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 12 replies
-
I want to get it to But I have not been able to achieve: display the task under the specified title |
Beta Was this translation helpful? Give feedback.
-
Thanks. This is the best I was able to manage - using a function showNotFullyCompleteTasksGroupedBySection(page) {
let all_tasks = page.file.tasks.where(t => !t.fullyCompleted)
if (all_tasks.length == 0)
{
return
}
dv.header(2, page.file.name)
// TODO this lists the sections in alphabetical order,
// but I wish to see them in the order they are
// in the file
for (let group of all_tasks.groupBy(t => t.section)) {
// This header shows a link labelled "File name > Section Name"
// TODO I would like it to show just "Section Name" in the hyperlink
dv.header(3, group.key)
dv.taskList(group.rows, false)
}
}
for (let page of dv.pages().sort(p => p.file.name, 'asc')) {
showNotFullyCompleteTasksGroupedBySection(page)
} Some example output: |
Beta Was this translation helpful? Give feedback.
-
Thanks for your anwers guys, I just recent see this post to do the same that you want but also did not find a solution that would allow me to solve the TODOs that you comment, after a while I found the next solution, first you must have the obsidian-tasks plugin installed and then with the following code you can use a combination of dataviewjs with the tasks plugin syntax to perform the grouped as you require, without showing the name of the file and the section thogether, also you have the power that the same plugin offers to be able to edit the tasks and other benefits, in this example i am showing the pending tasks, filtering and sorting by the "type" and "priority" metadata but you can replace by a tag or any other filter, for more references check this link
|
Beta Was this translation helpful? Give feedback.
-
For whoever gets here from google. You can also just do something like
The header starts with the filename, so it will naturally sort by file and then section. |
Beta Was this translation helpful? Give feedback.
-
So there's no way using regular dataview to do this? I'm not comfortable using js and would rather keep is really simple. I'm trying to do something similar. I have a task list in the top of the note containing the tasks and just want them separated by header ONLY, without the name of the file. Is there nothing I can do without js? Thx |
Beta Was this translation helpful? Give feedback.
-
This should work to group and sort the tasks by order of appearance of the sections and not alphabetically.
|
Beta Was this translation helpful? Give feedback.
-
Try this:
|
Beta Was this translation helpful? Give feedback.
This should work to group and sort the tasks by order of appearance of the sections and not alphabetically.
taskList
can contain tasks from multiple files as well, just change the firsttaskList =
line to get the tasks you want.