Dataview: Query the currently active (focused) file

Hey everyone,

Do you know if it’s possible to have a file with a dataview query that could query information dynamically from whichever file is currently in focus? So that the file with the dataview query could sit in another pane or in the sidebar and show results based on whichever other file i’m currently working on?

Cheers :slight_smile:

Hi. I’m not versed in JS, neither in DVJS and even less in API side.
But in Obsidian API we can find the app.workspace.lastActiveFile.
We can play with that, but it takes time to refresh (a dataview refresh issue) and I think we need to make some changes in the active current note to refresh the results in the note placed in the sidebar.

So, for test purposes, try this query (this is my first attempt…):

const ws = app.workspace.lastActiveFile
const title = dv.fileLink(ws.path)

dv.header(2, "Inlinks for " +  title)
dv.list(dv.pages("[[" + ws.basename + "]]");

dv.header(2, "About " +  title)
dv.table(["Name", "Creation Date", "Last modification"], dv.array( => [, p.file.cday, p.file.mtime]))

Thx again for the help!

This works great so far. It’s certainly enough for me to build upon it and work something out.
But I know even less about JS, DVJS etc. I usually just frankenstein stuff together and learn bits on the side =P.

Do you have an idea how to trigger a refresh for the query block without needing to update/modify the active / focused file or manually issue the “refresh blocks” command of dataview. Is there some trigger for changing focus or something like that?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.