Using frontmatter in dataview as a link

I use dataview to make indexes of my notes. The problem I had was that it also included the filename as a column, which is long and ugly to look at in a table query. The file name was also the link to the note. I wanted a property in the note’s frontmatter to serve as the link and the file column to go away. Thankfully, someone in the discord server provided a link to an AI programming assistant, with a little bit of back and forth with the AI I finally managed to solve the problem, here is the solution in case anyone else wants to use it.

Making the unwanted Files(N) column go away:
Use the following css snippet and that pesky unwanted column vanishes. I named it hide-column.css

.mermaid .bodyTable thead th:first-of-type, .mermaid .bodyTable tbody td:nth-of-type(1)  {
    display: none;
}
.dataview.table-view-table th:first-child,
.dataview.table-view-table td:first-child {
    display: none;
}

Accessing the frontmatter in a dataview query is easy; you just reference the particular property of the fontmatter. In my case the property I wanted to serve as the link to the note was “name:”, I have a bit of nostalgia for the 2E of D&D so I am building a vault just for the 2E. So here is the solution.

\```dataview
 table link(file.name, <property>) as "Field Name",  <property> as "Field Name", <property> as "Filed Name"
 from "path"
 where <conditions>
 sort <property> asc
 sorty <property> asc
\```

This will produce a three column table with the first column containing links to the notes using the frontmatter property specified, so that it only shows the data you want to see whilst still linking to your notes.

3 Likes

Default way to do that is to use:

https://blacksmithgu.github.io/obsidian-dataview/queries/query-types/#table-without-id

The default way using TABLE WITHOUT ID leaves the column header with the number of files and I did not want or need the file count to show. So my table looks like this:

Rather than like this:

It just makes that table look nicer.

1 Like

Dataview has a toggle for that: Display result count

3 Likes

Arg! That’s what I get for trying to solve a problem at ungodly hours. At least half of my solution is still in use. LOL. Now I’ve got to go change all my queries for the umpteenth time.

1 Like

Always good to have options and share insights. :handshake:

1 Like

True. At least I can add to my collection of snippets. Which comes in handy as I am building my own theme, and some of them I am learning what I can incorporate into the theme and which I cannot. Eventually, I will have to work on a custom plugin to go with my 2E vault. All the TTRPG plugins are 5E.

2 Likes

I liked the way you explained the anatomy of a query in the first post in this thread. Best wishes for your vault, work, and plans.

@ikeman32 Ahhh, this is exactly what I wanted. But my use case is totally different. I am using a list where I want to list the files but have the link as the frontmatter field title rather than the actual file name.

Thanks for the Share & Showcase :heart: