DataviewJS Snippet Showcase

I’m using a Mac, and Dataview is converting “Command” to “Control,” so when I have a hotkey at uses Ctrl-Cmd, it is listed and Ctrl-Ctrl. And more importantly, if it’s Cmd-O, it’s listed as Ctrl-O.

Is there something I could change to have the queries account for the Mac’s command key?


Hi everybody !

Would you know a method to use emojis as keys inside a dataviewjs query ?
I could write some successful queries using DQL but not with dataviewjs

Somehwere in my vault :

- [ ] [🗝:: value] Text

What I try to do :

let tasks = dv.array(dv.pages().file.tasks)

This doesn’t work and throws an error :

Evaluation Error: SyntaxError: Invalid or unexpected token

It would be even better if I could have a Yaml setting, such as :

filter : 🗝

Used in my dataviewjs query :

var filter = dv.current().filter;
let tasks = dv.array(dv.pages().file.tasks)

Many thanks in advance for your kind help

Solved by @TfTHacker himself, thank you so much !
For those who would be interested, the solutions are :

let tasks = dv.array(dv.pages().file.tasks)

and even the yaml filter thing works,

filter : 🗝
var filter = dv.current().filter;
let tasks = dv.array(dv.pages().file.tasks)

Generally this works great but for some reason, when I make a new note today I get this error (but it does not happen in the notes I created for all days earlier in this week …):

Evaluation Error: TypeError: Cannot read properties of undefined (reading 'file')
    at eval (eval at <anonymous> (eval at <anonymous> (app://, <anonymous>:7:36)
    at DataviewInlineApi.eval (eval at <anonymous> (app://, <anonymous>:15671:16)
    at evalInContext (eval at <anonymous> (app://, <anonymous>:15672:7)
    at asyncEvalInContext (eval at <anonymous> (app://, <anonymous>:15682:32)
    at DataviewJSRenderer.render (eval at <anonymous> (app://, <anonymous>:16267:19)
    at DataviewRefreshableRenderer.maybeRefresh (eval at <anonymous> (app://, <anonymous>:15995:26)
    at HTMLDivElement.i (app://

Oh, but of course a shutdown/re-open of Obsidian fixes this.


Just ignore the above error posting then …

Would love to have this snippet!

1 Like

I have not been able to get inline image to work with Blue Topaz theme. Do we have to specify anything to render images inline?

Hello everyone!

I created a dictionary that pulls all “terms” and “definitions” from my vault, but when there are more than one term and definition, they are all placed in the same table cell.

Here is my code

const pages = dv.pages().where(b => b.term)
		 .sort(a => a.term,'asc')
		 .map(a => [a.term,a.definition]))

and here is the output:

How can I break up that first row into individual rows?


I have this same question - it’s essentially like “flatten” in regular dataview, but I can’t for the life of me figure out how to do it into dataviewjs.

1 Like

Could you provide a small data example? I’m rather new to dataview (and Obsidian) and unaware how you could get a ‘term’ property on your pages and how the resulting data structure look like :x

General speaking, dv.pages() return a data array that again has a function flatMap. Maybe you get the wanted result when you use flatMap instead of map?

Also, for debugging purposes, it can be helpful if you assign pages.sort(a => a.term,'asc').map(a => [a.term,a.definition]) to a variable and then add a console.log(variableName) to your query. Hitting shift ctrl I in Obsidian opens the developer console whereas you’ll see your console.log call.
This way you can investigate how your resulting table data looks like and how the data differs when you get a single row per term/definion or one row with multiple term/definitions.

It could look like this then:

const pages = dv.pages().where(b => b.term)
const tableData = pages
		 .sort(a => a.term,'asc')
		 .map(a => [a.term,a.definition]);
console.log('tableData ->', tableData)
dv.table(['Term','definition'], tableData)

Hope that helps! :slight_smile:

1 Like

Hi! I made a DataviewJS snippet that automatically adds people’s birthdays in your daily notes upon creation, if it exists, like so:

It uses the file’s alias, but I added an option in the code to use the file name instead.

Credit goes to @Moonbase59’s code here, I only added small modifications, hope that’s okay!

Here’s the gist with setup and instructions:


This is very useful – thank you for sharing it. I already have a People folder, and in it the individuals have birthDate: in the yaml. Which bits of your template should I change to accommodate this?

Please tell me how can I learn about the obsidian dataviewjs plugin from the beginning. I am from a non-coding background and don’t know javascript. But I am interested in learning this plugin.

If you haven’t already read them, the docs are a great place to start: Dataview

Hi Saari,

Here is a scenario. I am reading a textbook and want to write down a definition. I write:

term:: "Name of Term"
definition::"Definition of Term"

In some notes I have multiple terms and definitions, and that is when they all seem to be placed in the same entry.

Thank you for showing me how to debug.

1 Like

Change all instances in the code from p.birthday to p.birthDate and it should work.

1 Like

YAS! ^this, plez


Hey! Trying to figure out how to do a combination of:

  • Display taskLists with groupByFile = true
  • Group the files of the taskLists by a custom YAML field
  • Filter out files of the taskLists by a custom YAML field

What I thought would work is:

for (let group of dv.pages().where(p => p.category.contains("project") && p.status.contains("active")).groupBy(p => {
	dv.header(3, group.key);
	.sort(t => t.completed))

It only works if I put something inside dv.pages(), and limit the contains() statement to a single filter, e.g. only .where(p => p.status.contains("active")). The thing is, I don’t have tags on the pages I’m filtering on (only YAML fields), and I’d prefer to filter with contains() statements on YAML than by adding tags.

My files I’m intending to query here look something like this

category: project
status: active
kr: [[Fly to mars]]
# Project
- [ ] Task

Any suggestions for a fix?

Btw my error message is “Evaluation Error: TypeError: Cannot read property ‘contains’ of undefined”

1 Like

Hi, does anyone know how to use taskList, but have it not include sub-bullet-points located directly underneath the task? For example, I have tasks that are structured like this:

- [ ] Actual task that I want to appear in taskList
    - Example contextual note I included as sub-bullets
    - Note that these are not tasks / sub-tasks since they lack leading brackets
    - However, taskList still displays them and makes the view too busy

I’ve noticed that those sub-bullet records are stored in the data array with a value for real equaling ‘false’. So I tried to filter for only real == true in the where section, but no luck.

dv.taskList (dv.pages('#tag').file.tasks.where(t => !t.completed && t.real)