you can turn off “automatic view refreshing” in the dataview settings.
sometimes I do want to refresh the results. For this I have the following templater code in a template file: <%*app.workspace.activeLeaf.rebuildView()%>
(templater plugin required)
I then bind the inserting of that template to a shortcut, and hit that shortcut every time I want to refresh the dataview block.
If you want to run something once through dataview, you could also trigger the query from Templater and use the markdown* variants of the display functions. This way you never see the source code again, and it’s fully replaced by its result.
@holroy Hi, do you have an example or some documentation link ?
I’m not that familiar with templater, I thought it was only used with shortcut or new document.
Here I just paste in an existing document.
And whenever I try to use the templater syntax, I only get it as text, nothing happen
If you something like the following in a file, i.e. myAliasesTemplate:
<%*
const dv = this.app.plugins.plugins["dataview"].api;
const query = 'LIST aliases WHERE aliases LIMIT 5';
const result = await dv.queryMarkdown(query);
if ( result.successful ) {
tR += result.value
} else {
tR += "~~~~\n" + result.error + "\n~~~~"
}
%>
Alternatively, you could write the query as:
const query = `
LIST file.mday
LIMIT 10
`
Or if you’re already using dv.table() or similar, then just do that script, and replace the dv.table() with dv.markdownTable() (see Markdown renderers ).
After you’ve written your template goto Settings > Templater > Template Hotkeys, and add your template into a line there, and click the + icon, which opens up the Hotkeys dialog, where you can locate your template and hit another + icon and choose the hotkey combination you’d like to trigger this template.
Instead of the above, you could also if you run your template just every now and then, go to the Command Pallete, and do the Templater: Open Insert Template modal (or choose your template if you added to the previous list).