Skip to content

Dataview

Chris Gurney edited this page May 29, 2025 · 77 revisions

Install and enable the Dataview plugin ↗ and use Note Toolbar to run queries, evaluate expressions, and execute scripts (like with dv.view).

Note Toolbar's Scripting option must be enabled in order to use this feature.

Tip

See the examples folder in this repo for example scripts ↗ that work with Note Toolbar. See also the Example Vault for Dataview Queries ↗ and the Basic Dataview Query Builder ↗ thanks to @s-blu.

Use Dataview expressions in any toolbar item

You can use Dataview expressions in labels, tooltips, and URIs, to create dynamic toolbars. (Dataview JS expressions are not supported.)

For example, set your label to =dateformat(date(today), "MMM d") to show today's date, right in your toolbar (assuming your Dataview prefix is set to =). Alternately use this syntax: {{dv: dateformat(date(today), "MMM d")}}

Another example that shows the number of days from today to some date property in the note: {{dv: durationformat(dur(this.somedateproperty - date(today)), "d") }}

Functions available

After creating a new Dataview toolbar item, select from one of the below functions.

Execute query

  • Executes the provided query and renders the result.
  • Uses the queryMarkdown API method.

Query example:

TABLE file.mtime AS "Last Modified" 
FROM "SomeFolder" 
SORT file.mtime DESC

Execute JavaScript file

  • Executes the provided script file, much like dv.view() (but missing the CSS features).
  • Parameters can be passed in JSON format, e.g., "name": "Chris"

JavaScript file example:

dv.paragraph("👋 Hello note!"); // must use Output callout ID for this to appear
console.log("👋 Hello console!");
new Notice("👋 Hello notice!");

JavaScript file with parameters:

(async () => {
    let name
    if (input) {
        ({name} = input)
    }
    console.log(`👋 Hello ${name}`);
    new Notice(`👋 Hello ${name}`);
})();

JavaScript file with parameters, with Dataview output:

// Shows a list of files in the specified folder (and subfolders).
// Excludes the current file. Defaults to current folder if folder not provided. Sorts alphabetically.
function FileList(input) {
    let fileFolder

    if (input) {
        ({fileFolder} = input)
    }
    /* if fileFolder is not provided... */
    else {
        /* ...default to the folder of the calling note */
        fileFolder = dv.current().file.folder
    }

    const files = app.vault.getFiles()
        .filter(file => file.path.startsWith(
            fileFolder.endsWith("/") ? fileFolder : fileFolder + `/`) && 
            (file.path !== dv.current().file.path))
        .sort((a, b) => a.name.localeCompare(b.name))

    dv.paragraph("📂 `" + fileFolder + "`:")
    dv.list(files.map(file => dv.fileLink(file.path)))
}

FileList(input)

Evaluate Dataview expression

  • Interprets the provided Dataview expression and returns the result.
  • Uses the evaluateInline API method.

Dataview expression example:

dateformat(this.file.mtime, "yyyy.MM.dd - HH:mm")

Evaluate Dataview JS expression

  • Interprets the provided Dataview JS expression and returns the result.
  • Uses the executeJs API method.

Dataview JS expression example:

dv.el('p', dv.current().file.mtime)

Note Toolbar Callout support

For Note Toolbar Callouts, use these data attributes:

Function data-dataview data-expr data-src data-args data-callout
Execute query query query n/a n/a callout ID (optional)
Execute script exec n/a script filename arguments (optional) callout ID (optional)
Evaluate Dataview expression evaluate expression n/a n/a callout ID (optional)
Evaluate Dataview JS expression executeJs expression n/a n/a callout ID (optional)

Example:

> [!note-toolbar] Dataview Toolbar
> - [Dataview Query Example]()<data data-dataview="query" data-expr="TABLE file.mtime AS &quot;Last Modified&quot; FROM &quot;Templater&quot; SORT file.mtime DESC" data-callout="asf"/>

Where does output go, and where are errors reported?

For how output and errors are handled, see Executing scripts.


Next: File items

Learn more: Executing scripts

Clone this wiki locally