DataView Help Request

What I’m trying to do

I am trying to do similar to what is described here - but in my daily notes, I am tagging “#to/research” ideas. They will be in individual daily notes, so the end goal is to have it look just like his where I have a master note with the dataview query, broken down by days (the daily notes as headers) and underneath each are the uncomplete blocks with the tag #to/research

Things I have tried

I tried copying his code: ```dataviewjs
dv.taskList(dv.pages(“#to/research”).file.tasks
.where(t => t.text.includes(“#to/research”))
.where(t => !t.completed))


Nothing happened in the note. Not sure why the error.
1 Like

Hello.

  1. Make sure Obsidian > Settings > Dataview > Enable JavaScript Queries is toggled on.
  2. The text below should work. Use ‘paste as plain text’ or ‘paste and match style’ to retain all the formatting when copying from the forum to a local note.
- [x] #to/research an idea
- [ ] #to/research a second idea
- [ ] #to/research a third idea

## query

```dataviewjs  
dv.taskList(dv.pages("#to/research").file.tasks  
.where(t => t.text.includes("#to/research"))  
.where(t => !t.completed))
```

You could also just do this with a regular Dataview query:

```dataview
TASK
	from #to/research
WHERE
	!completed
GROUP BY
	link(file.name)
SORT
	file.name 
	ASC
```

Amazing! That worked, thank you very much! Simple fix.

What do you see as the benefit of regular Dataview query versus using the Javascript query, if any, besides personal preference of code writing? @anon63144152

1 Like

Also, if I were to not have it filter/search by tasks, and instead they were just line-items, such as:

  • #to/research XYZ
  • #to/research ABC

What would I change in the JS + normal DV query code?

1 Like

Hello.

1. DQL and JS

The user notes have the following:

There are three different ways you can write a Query: With help of (1) the Dataview Query Language, (2) as an inline statement, or (3) in the most flexible but most complex way: as a Javascript Query.

Being a novice, I have stuck to using simpler DQL and inline statements only.

Dataview is also going to be replaced by Datacore, so I am not bothering to focus too much on Dataview any more.

2. Lists

With plain lists, the following appears to work (you would need to change the FROM statement to point to the folder in your vault that you want to query). With this format, it is impossible to mark tasks as completed.

I don’t know how to do this with JS. Hope someone else can help.

- #to/research XYZ
- #to/research ABC

# query

```dataview
LIST
	L.text
FROM 
	"_inbox"
FLATTEN 
	file.lists as L
WHERE 
	contains(L.tags, "#to/research")
LIMIT 
	50
```

1 Like

One way, without any error checks, could be:

```dataviewjs
dv.list(dv.pages('"_inbox"')
  .flatMap(p => p.file.lists)
  .where( i => i.tags.contains("#to/research") )
  .map(i => new ListPairWidget(i.link, i.text)))
```

Note however that compared to the tasks queries above this would link to just the file, and not the exact line of the task. This can be a little better using either i.section or i.header in that last line, but it’ll still not go directly to the exact line.

From my point of view I also see that DQL queries are somewhat easier to get started with, while doing the DVJS (or dataviewjs queries) requires more knowledge of javascript and require a lot more fiddling about to get them correct. They’re more powerful in some ways, but that do require even more coding knowledge.

Another markup, see here for more information, is to use task decorations, and mark these up as ideas, using something like:

- [I] An idea
- [I] A second idea
- [I] a third idea

And then use a query like:

```dataview
TASK WHERE status = "I"
```

To get this output (if using the Minimal theme):
image

2 Likes

Hope that helps the OP. Thanks.

1 Like

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