-
-
Notifications
You must be signed in to change notification settings - Fork 12
Dataview
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.
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") }}
After creating a new Dataview
toolbar item, select from one of the below functions.
- 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
- 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)
- 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")
- 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)
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 "Last Modified" FROM "Templater" SORT file.mtime DESC" data-callout="asf"/>
For how output and errors are handled, see Executing scripts.
Next: File items
Learn more: Executing scripts
User Guide • Gallery • Note Toolbar API • Support • Discussions ↗ • Release Notes ↗ • Roadmap
Note Toolbar by Chris Gurney • Buy me a coffee ☕️