Extracting a row of data from Dataview

The gist of the idea is as follows:

  • Do the full list query within dataviewjs, and store the list in fullList
  • Then just filter out the information you want, aka fullList.filter(... ) into
  • Present the data again, using dv.table()

Here is something to explain how to do this:

```dataview
TABLE WITHOUT ID mood, moody
FROM "ForumStuff/f52118"
WHERE mood
```

A random table, which produces this output in my test vault:
image

And now the real script, where I want to filter out any moody larger than 10, you’ll get to adapt to your situation. :slight_smile:

```dataviewjs
// Get the full list
const pages = await dv.query(`
TABLE WITHOUT ID mood, moody
FROM "ForumStuff/f52118"
WHERE mood
`)

if (pages.successful) {
  // Filter out the result you want, remember that the first column is 0
  const filtered = pages.value.values
    .filter(r => r[1] > 10)
  
  // Present the result
  dv.table(pages.value.headers, filtered)
}
else
  dv.paragraph("~~~~\n" + pages.error + "\n~~~~")
```

Which aptly produces:
image

Hope this helps, now I’m going out for pizza!

3 Likes