Summary
I would like to create a dataview query which uses category notes as the group headers and lists all linked subcategories within the group contents, and which does this dynamically so I don’t need to create separate queries for each new category added.
Context Explanation
I have notes in my vault organized by primary and secondary categories (e.g., categories and subcategories). Each secondary category is linked to a primary category, and one primary category would have multiple subcategories. All of these are notes, and then individual notes within my vault link to the relevant primary and secondary categories.
For Example:
Primary category note named
01-Animals
Secondary category notes02-Lions
,02-Tigers
,02-Bears
– all linked to01-Animals
Then an atomic note would include the following content (not front matter – actual note content):
(Note title, such as “Study of interesting pack behaviors of lions”)
Primary Category: [[01-Animals]]
Secondary Category: [[02-Lions]]
(Note contents… etc…)
There are obviously multiple primary categories. The secondary categories are added organically as a new subtopic area comes up.
Finally, since I’m using templates for each note type, the primary and secondary category notes can be easily identified because they use the tags #PrimaryCategory
and #SecondaryCategory
, respectively
My Question
Is there a way to use dataview, perhaps specifically the dataviewjs ‘group’ capability, to dynamically generate a table/list/whatever which uses the Primary Category notes as group headers then lists all associated Secondary Category notes within that group?
I’m thinking something along the concept of the output shown here. Except instead of the subject being the group header, it’s the primary category note. Something like this:
01-Animals
01-Plants
- 02-Trees
- 02-Flowers
- (etc…)
Is something like this at all possible? How might I go about it?
My initial thought for pseudocode logic (and this is definitely not dataview or dataviewjs format-ready) would be along the lines of:
for (let group of dv.pages("#PrimaryCategory").groupBy(p => p.file.link)) {
dv.header(3, group.key);
# Pseudocode starts here!!!
dv.table(
from [[group.key]] and "#SecondaryCategory"
)
}
Thoughts? Suggestions? Thanks in advance!