Create dv.table with entries grouped by headers. The headers are determined by the names of files that contain specific tags

What I’m trying to do

I have two sets of markdown files:

  1. The first set consists of files dedicated to organizations. Each file corresponds to exactly one organization: “world bank”, “united nations”, etc.

  2. 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}]]`]
))
}

You say that each country has one or more organisation as tags, but can they have other tags?

How do you differ between the country notes, and the organisation notes? How are they marked?

Basically this seems like the query should just do a flatten on the tags, and then list all the tags (with corresponding notes) that are organisations.

Yes, country notes can have other tags.

To differentiate between country and organization notes, I just use different tags. For example, for countries I use “#type/country” and for organizations I use “#type/organization”. For this reason, I don’t think your suggestion would work because country notes are not tagged with “#type/organization”.

Sorry if my writing was not clear, but for my use case a country can belong to any number of organizations, but the produced table should have the name (or file name) of each organization listed only once.

Who (or how do you) determine the tag to be used for an organisation with spaces and/ir capital letters in its name? In other words, how reliable is the tag to determine the organisation name?

If not reliable, what is your idea to link back from a country to an organisation?

I’m already thinking you would make it a whole lot easier for yourself if instead of tagas you had a dedicated field listing the organisations that country was a member of. Is that something you’re willing to consider?

Trying to keep the example simple, I didn’t mention the details of my actual setup. To link back from a country to an organization reliably, what I do is use fixed random filenames, kinda like Luhmann-style. So, for the note “United Nations,” I use 23110xh as filename. Then, to relate a country to it, what I do is add a tag to, say, the note for Argentina as “#related/23110xh”. Therefore, if two country notes have the tag “#related/23110xh”, they should show up in the table under the header for “United nations”.

I wouldn’t mind having a dedicated YAML field for specifying the relations between notes, but I don’t understand how that would help. My knowledge of JavaScript is rudimentary at best, but aren’t tags just like any other YAML fields with multiple values?

Yes, and no… Since tags can hold many tags where the context is not given as to their meaning, they sometimes come short of a dedicated field with multiple values but they all have the same meaning.

Lets say you’ve go this YAML:

---
tags: related/23110xh, related/12345yi, fruit, circle
organisation: 23110xh, 12345yi
---

It’s harder from a query context to single out the two related tags connecting that yaml to the organisations, rather than knowing that all values of organisation are organisations tags.

Related to your query it comes down to when looking through all the country files, which tags from are you to choose as organisation-tags, and how do you link them to their organisational file.

If the country file had the actual file name of the organisation, you could do something like:

  • For each country, flatten the organisation field into its separate values, and look up the file with that name
  • Sort and group the all files related to organisation and secondary the country

With just a loose reference, which is not a file name (or can be translated into a file name, you need to do a double query:

  • List all organisation, and make a list using the related tag as key
  • In the other query, go through all countries and check if any of the tags matches against an organisational tag, and keep these
  • Now sort the remaining files, and group according to organisation and country

The first variant can be done using a standard Dataview ( DQL) query, the second variant needs to be done using dataviewjs and some scripting of that intermediate list to connect country and organisation.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.