OS TechBlog
Published in

OS TechBlog

How to get started with Obsidian Dataview and DataviewJS

In a previous OS TechBlog post we introduced Obsidian as a note-taking app. Here I will take you to the next level of organising your notes, with the Dataview plugin for Obsidian. This is one of the ultimate tools for linking your thinking and pulling it together in different ways.

If you haven’t read Obsession with Obsidian I can highly recommend it as a great introduction to Obsidian.

Get Started Simply

To try out these examples and tips you will need to download and install Obsidian and then install the Dataview plugin, both of which are free.

If you haven’t installed a plugin in Obsidian yet follow these steps after installing and opening Obsidian:

1. Click the cog (settings icon) in the bottom left.
2. Click Community Plugins, in the window that opens, and turn off safe mode if it is on.
3. Click the browse button and search for ‘dataview’ in the search box.
4. Click on the Dataview plugin, then the Install button and finally the Enable button.

Dataview, in the words of its creator, allows you to

“Treat your Obsidian Vault as a database which you can query from”

With Obsidian built on top of a graph database, this makes total sense.

Here are a few examples of how we can query our Obsidian notes using the Dataview Query Language (note: I will expand on how you can use JavaScript later in this article):

Using Built-In Obsidian Metadata

The following will list the files in a folder called technology, along with the file creation time and date, and order them by creation time in descending order.

```dataview
table file.ctime as "Created Time"
from "tech"
sort file.ctime desc
```
Screenshot showing a Dataview table listing files from the ‘tech’ folder, ordering descending by created datetime, and using in-built metadata from the file to show the ‘created time’ of the file as a column.
Dataview table listing files from the ‘tech’ folder, ordering desc by created datetime

You can list all the files in your Obsidian vault very simply:

```dataview
list
```
Screenshot of a Dataview list of all notes in the current Obsidian vault, with each note title shown as a link next to a bullet point.
Dataview list of all notes in the current Obsidian vault

Using tags and your own meta-data

With Obsidian you can add tags to a file, either by typing them with a #, e.g. #myTag or by including it in a front matter section using YAML (see below). This is also where you can include your own custom metadata.

Example YAML

---
tags: ['myTag', 'AnotherTag']
type: 'review'
rating: 4
---

So if I have some reviews I have written I can collect them together in a table:

```dataview
table rating as "Rating", dateRated as "Date Rated"
from "music"
where type = "review"
sort rating desc
```
Screenshot showing the Dataview table of notes in the music folder with custom metadata from YAML in the notes used to create a ‘rating’ and ‘date rated’ column for each note.
Dataview table of notes in the music folder with custom metadata from YAML in the files

As you can see you can get very clever with how you add and use your own metadata.

Tasks

If you have created tasks in your Obsidian notes then Dataview can collect them together in clever ways.

Perhaps you want to create a task dashboard. Here is a really simple example of how to create two separate lists of tasks from files with different tags, and you can check off or un-check the tasks in the list too:

```dataview
task
from #ukulele
```
---
```dataview
task
from #research
```
Screenshot showing how Dataview renders the list of tasks from notes with the tag ‘ukulele’ and ‘research’. Showing three sub headers for ukulele notes and three sub headers for research notes, with one or more checkboxes under each with the task next to them, some checked.
Dataview tasks from two specified folders

A Step Further: DataviewJS

For those of you wanting more here is a quick introduction to using DataviewJS. It is similar to Dataview but using JavaScript to access the API that Dataview exposes.

Using JavaScript we can refine the task list further, by eliminating tasks we have already checked, and even showing all our checked tasks together:

```dataviewjs
dv.header(2, 'Ukulele Tasks');
dv.taskList(dv.pages('#ukulele').file.tasks
.where(t => !t.completed));
```
Screenshot showing how Dataview renders the list of tasks from notes with the tag ‘ukulel’. Showing a main header ‘ukeleletasks’, and three sub headers of the note names with one or more checkboxes under each with the task next to them.
Not-completed Dataview tasks from notes with the tag ‘ukulele’
```dataviewjs
dv.header(2, 'Research Tasks');
dv.taskList(dv.pages('#research').file.tasks
.where(t => !t.completed));
```
Screenshot showing how Dataview renders the list of tasks from notes with the tag ‘research’. Showing a main header ‘research tasks’, and three sub headers of the note names with one or more checkboxes under each with the task next to them.
Not-completed Dataview tasks from notes with the tag ‘research’
```dataviewjs
dv.header(2, 'All Completed Tasks');
dv.taskList(dv.pages().file.tasks.where(t => t.completed));
```
Screenshot showing how Dataview renders the list of completed tasks from all notes. Showing a main header ‘all completed tasks’, and two sub headers of the note names with one checked checkbox under each with the task next to them.
All completed Dataview tasks

But my favourite way of using Dataview is to create whole notes from metadata, essentially creating a dashboard or user interface to my stored data. More to come in another article, but below is an example for the curious.

Note structure for a training provider

The content of this note is created completely by Dataview, using custom metadata in YAML:

---
type: 'training provider'
tags: ['training', 'provider']
website: 'https://www.pluralsight.com'
title: 'Pluralsight'
---
```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity

dv.header(1, pg.title); // print the page title from YAML as H1
dv.header(2, 'Website'); // print 'Website' as an H2
dv.paragraph(pg.website) // print website url from YAML in a paragraph

dv.header(2, 'Courses Taken:'); // print 'Courses Taken' as an H2
dv.list(dv.pages('#training').where(p => p.provider && p.provider.contains(pg.title)).file.link);
```
Screenshot showing the Dataview rendering of metadata from YAML in the same page and other pages. Showing a main header of the training provider name, sub header of ‘website’ and then the website url taken from the note’s YAML, then a sub header of ‘courses taken’ and below it a bullet list of links to notes on courses taken from this training provider.
Dataview rendering of metadata from YAML in the training provider note and listing connected notes

And structure for notes on a course from a training provider

Again, the content is displayed completely by Dataview:

---
type: 'training notes'
tags: ['training', 'notes']
courseTitle: 'How to Be a Great Mentor: Get More out of Mentoring'
link: 'https://app.pluralsight.com/library/courses/how-to-be-great-mentor'
provider: 'Pluralsight'
---
```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity

dv.header(1, pg.courseTitle); // print the course title from YAML as H1
dv.header(2, 'Link'); // print 'Link' as an H2
dv.paragraph(pg.link) // print website url from YAML in a paragraph
```
## Notes
- my notes
- in this
- section
---```dataviewjs
let pg = dv.current(); // set pg to be the current page, for brevity

dv.header(2, 'Other ' + pg.provider + ' Courses Taken:'); // print 'Other <provider> Courses Taken' as an H2
dv.list(dv.pages('#training').where(p => p.provider && p.provider.contains(pg.provider) && p.file.name != pg.file.name).file.link); // print other courses by the same provider, excluding the current page
```
Screenshot showing the Dataview rendering of metadata from YAML in the same page and listing links to other courses based on YAML in other pages. Showing a main header of the course name, sub header of ‘link’ and then the website url taken from the note’s YAML. Next a sub header of ‘notes’ and below it a bullet list of notes written in this file, then a sub header of ‘Other Pluralsight courses taken’, with Plurasight taken from YAML, and below it a bullet list of links to those courses.
Dataview rendering of metadata from YAML in the course notes note and listing connected courses

What’s next?

I hope you can now see just some of the potential for using Dataview with Obsidian to harness the data in the underlying Obsidian graph database.

Have a go and implementing the above, if you haven’t already, and experiment with your own use cases.

In a later post, we will look in more depth at Dataview and DataviewJS and some more advanced examples.

Here are some useful links to the Dataview Documentation, which contain more examples:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jacqui Read

Jacqui Read

102 Followers

a thought-leader in #communication #design, living #architecture #documentation, and #agile feedback. #Sustainability #Productivity #WomenInStem