What I’m trying to do
I have two sets of markdown files:
-
The first set consists of files dedicated to organizations. Each file corresponds to exactly one organization: “world bank”, “united nations”, etc.
-
The second set consists of files dedicated to people who belong to one or more of the organizations in the first set. Each file corresponds to only one person: “Country A”, “Country B”, etc.
To mark the relationships between (1) and (2), I tag the notes in set (2) with the names of the files in (1). For example, if “Country A” belongs to the “united nations”, then its corresponding note will be tagged: “#united_nations”.
I am having difficulty creating a dv.table where each header is named after each of the organizations in set (1) followed by the list of all countries in set (2) that belong to that organization.
My problem is that I don’t know how to code the groupings in dataviewjs because I only know how to group according to elements (properties, tags, etc.) in single files.
I need dataview to determine the headers dynamically by determining which markdown notes correspond to organizations (by having, for example, the tag “#organization”), and then make a list of all organizations which will be used as headings/groupings.
The result should be something like:
- Header : Organization 1
Country A
Country B
Country C - Header : Organization 2
Country B
Country C - Header : Organization 3
Country A
Country C
etc.
Things I have tried
I was trying to use this as a model. It is a dataviewjs snippet that produces a table that groups the bibliographic references of a specific author (or authors) by text_type (book, article, interview). The text types (book, article, interview, etc.) are the headers, which are followed by the markdown files whose properties correspond to said text type. For example, if a file contains the property “text_type: book” in the YAML frontmatter, it will appear in the table under the header “book”.
The problem with adapting this model is that in my query, the groupings/headers have to be determined by dataview by seeing which files contain certain tags that I specify (for example “#organization”, “#latin_america”, etc.)
let pages = dv.pages("#reference and #author/einstein_albert");
for (let group of pages.groupBy(p => p.text_type)) {
dv.header(3, group.key);
dv.table(["Date", "Title"],
group.rows
.sort(p => p.date, 'asc')
.map(k => [k.date, `[[${k.file.name}|${k.title}]]`]
))
}