-
Hi everyone! I’m trying to sort text and tasks based on the assigned tag or tags and have them listed in the order they appear in the file beneath the correct heading. I found this dataviewjs search query below written by user ces3001 in this thread How to group tasks by File and then by Section? ####720. I wonder if someone could explain how this works and how I can modify it to add a search for a specific tag or tags. Basically:
To summarise: I want to do the following using dataview:
So for example, if I have a document with 1000 tasks, and 15 of them are tagged with #example-tag-1, located beneath three different headings, I want to show ONLY those 15 tasks in their correct order under the correct heading. I also want to be able to search for multiple tags at once and show only those tasks that are tagged with these tags. I explain what I'm trying to do more in detail here. This regular search query below almost does the job, except it lists the headings in the wrong order (alphabetically instead of how they appear in the document). See this screenshot from Obsidian!
Does anyone know how to modify this JavaScript search query above to fit my needs? Help would be much appreciated! // Cheers |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The grouped headings sort issue seems to originate from DataArray.groupBy. The workaround here is to provide a comparator that preserves the original order. const data = dv.current().file.tasks.filter(t => t.tags.contains('#example-tag')).groupBy(t => t.section.subpath, (a, b) => a === b ? 0 : 1)
dv.taskList(data) |
Beta Was this translation helpful? Give feedback.
To choose an arbitrary file from your vault, replace
dv.current()
withdv.page('path/to/file')
.To filter tasks containing
every
one of the specified tags, replacetasks.filter(...)
with:Bonus tip: to filter tasks containing
some
of the specified tags, use same code replacingevery
withsome
.