Refresh and toggle dataview/source

@holroy very, very cool solution you have above to your problem.

I came across this thread while searching for how to create an auto-refreshing Dataview query (e.g. something that refreshes every 1 second or 5 minutes, etc).

I eventually figured it out, and while it isn’t related to your post I thought you might be interested.

edit: Skip down to my later post, it has a much better solution.


This example will show a clock that updates every second:

```dataviewjs
let el
const repeat = setInterval(() => {
  if (el && !el?.checkVisibility()) {
    // Clear the repeat if the note is no longer open
    clearInterval(repeat)
  } else {
    // Remove the current contents of the Dataview block
    // so that we can replace it with new contents
    dv.container.innerHTML = ''
    el = dv.el('div', '')
    
    // Put all your Dataview output here
    dv.header(5, 'This time will keep updating while the note is open:')
    dv.paragraph(moment().format('HH:mm:ss'))
    console.log(moment().format('HH:mm:ss'))
  }
}, 1000)
```
2 Likes