Dataview - All tasks not completed

 ```dataview
  task 
  ```

This will display all tasks completed and not.

How do I only display not completed tasks?

2 Likes

You can ask to plugin developer in GitHub page (GitHub - blacksmithgu/obsidian-dataview: A complex query language implementation for the Obsidian note-taking tool.).
Since the version 0.3.6 the developer introduced the feature “Task lists now include task context (non-task parents/children)”. But none extra information in plugin documentation (https://blacksmithgu.github.io/obsidian-dataview/docs/intro).

EDIT: There’s some information in the JavaScript API documentation, but I don’t have knowledge in JS query language.

I could only find a reference to a “groupByFile” option, which will render the filename containing the task. I’d love to get the header above the task (which is the column name if you use the Kanban plugin).

As I said before, JS is not my ground! :slight_smile:
I see another limitation: children tasks are not filtered.

Considering my limitations in the plugin, I suggest two ways:

  1. If you have only ‘parent’ tasks, you can try something like this:
```dataviewjs
	dv.taskList(dv.pages().file.tasks
	.where(t => !t.completed))
  1. If you have ‘children’ tasks, then you can adopt a ‘tricky’ solution with css snippets.
  • create a cssclass in frontmatter:
---
cssclass: hidetasks
---
  • write a simple dataview query:
```dataview
	task
  • create a css snippets with this:
/* hide checked tasks */
.markdown-preview-view.hidetasks ul > li.task-list-item.is-checked {
  display: none;
}

This affects all the content of the note with the cssclass defined, that is, all the checked tasks on this note are hidden.

6 Likes

Hey thanks, your first solution:

```dataviewjs
     dv.taskList(dv.pages().file.tasks
     .where(t => !t.completed))
```

works perfectly.

I do have a follow up question.
I have a file called “Journal Template.md” with checkboxes that I do not want to appear. I’ve tried this code:

```dataviewjs 
dv.taskList(dv.pages().file.tasks .where(t => !t.completed)) &&
dv.page(!"Journal Template.md")
```

as well as others and it does not work; the check boxes from the “Journal Template.md” keep appearing.

What am I doing wrong?

As I mentioned before, my knowledge in dataview javascript language is almost zero!
Said that, by the logic I think you need to write the ‘source conditions’ in the first dv.pages(). Try this:

```dataviewjs
 	dv.taskList(dv.pages("![[Journal Template]]").file.tasks
	.where(t => !t.completed))

(I didn’t test this…)

Well, I appreciate the effort, but that refuses to work.

Sorry, this is beyond my limited knowledge.
I can only suggest this: if your file “Journal Template” is inside one folder that you don’t want to include in your search (e.g. folder “Templates”), then you can exclude that folder (and all files inside that folder).

```dataviewjs
	dv.taskList(dv.pages('!"Templates"').file.tasks
	.where(t => !t.completed))
  • If you use the expression ('"Templates"') the search is limited to folder Templates;
  • If you use ('!"Templates"') or ('-"Templates"') the search excludes that folder.
1 Like

Or, returning to the way to exclude a specific file:

```dataviewjs
	dv.taskList(dv.pages().file.where(f => f.name != "Journal Template").tasks
    .where(t => !t.completed))

Thank you, the second one worked. Very helpful.

I’ve found it helpful at times to move the pages() parameter into the where clause, like this:

```dataviewjs
	dv.taskList(dv.pages()
            .file.where(f => !f.path.includes ("foldernamehere")
            .tasks.where(t => !t.completed))
```

Basically it gets all the files for all pages, then filters out anything that doesn’t include “fildernamehere” in the full path of the file, then filters out completed tasks.

You can also perform other operations on the file component, like “f.name”

4 Likes

Thanks for the descriptive explanation. I really appreciate that.
I’m a newbie in all this stuff (code languages, etc.) trying to capture some information for my own use of Obsidian.
The Dataview plugin has a tremendous potential. But for ‘non-coders’ the approach is no easy.
For now the generic approach (dataview) is less complex and more or less accessible through the plugin documentation. But the approach via javascript (dataviewjs) is much more complex and the plugin documentation is very uncompleted for ‘code-newbies’. Much complex but certainly more rich in potential.
In my personal use I don’t use (yet) this approach because all these limitations. I want to but the learning curve is in another level. This help call was a pretext to start this (long) learning.
Thanks.

EDIT: Just one question: when you write “foldernamehere” works too with “filenamehere”?

1 Like

You might consider using the Tasks plugin - much easier to use for filtering tasks various ways.

Thanks for posting this! I didn’t know you could filter at the task level inside a dv.taskList(). Super helpful!

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