Dataview plugin snippet showcase

Have been looking for a solution to this for a while now. Thanks, thanks and thanks! :slight_smile:

1 Like

Hi All,

Just another very simple one I could do with some help on please!

I have some custom YAML fields:

ECLAM:
- Module_5

And would like to create an MOC from a Dataview query where it displays the file.names of all the notes which have the ECLAM Module_5 reference in their YAML, I have one test note with ECLAM: - Module_5 in the YAML and have the following query:

dataview
list where ECLAM ="Module_5"
sort file.name asc

But get zero results?! Could someone please help?

Thanks

Jim

1 Like

We can do it with contains.

```` dataview
list where contains(ECLAM, "Module_5")
sort file.name asc
````

If you were to find every file that has ā€œECLAMā€ in it, it would simply be:

```` dataview
list where ECLAM
sort file.name asc
````

Tell me how it goes!

Perfect thank you @veradrawer - that works perfectly for my original questionā€¦

I was wondering whether I can refine it further!! Can I add multiple ā€œECLAMā€ sections within my YAML? For example:

---
ECLAM:
 Module: 5
 Keyword: imaging
---
  • Is this possible?
  • What would a query for ECLAM ā€œModule 5ā€ look like if I did this?!

Thanks again everyone!!

Jim

As far as I know indented metadata is not supported in the obsidian yaml. The way Im doing it looks like:

---
ECLAM:
- 5
- imaging
---

and then

```` dataview
LIST
WHERE contains(ECLAM, "5")
SORT file.name asc
````

If you would want to have both:

```` dataview
LIST
WHERE
	contains(ECLAM, "5") AND
	contains(ECLAM, "imaging")
SORT file.name asc
````

You can change the AND for OR, and if you would want to get from Module 5 but not from imaging you would have to add an exclamation mark like !contains(ECLAM, "imaging".

1 Like

On further note, I use two fields in every note: noteType and noteClass.

noteType helps me group the type of note it is in the Luhmannā€™s model of _permanent, _literature and _fleeting; while noteClass defines the actual content of the note, having such as _moc, _quote and so on.

So when I want to do a query, I start by defining the noteType, and if needed, the noteClass. A simple way of knowing things is by those things not done, so if Iā€™m looking for fleeting notes, I simply search for notes that have neither the noteType attribute (not propperly filled yet) or have it declared as _fleeting.

Hope itā€™s useful.

Hi, I am creating a work log for my projects using DataviewJS, yet I canā€™t figure out some sorting issue by myself. It would be great if you can give me some advice.

Here is my code. I customize it from @Wenā€™s post.

for (let group of dv.pages('"Project"').where(p => "goal" in p && (p["brand"] == "Scutum")).groupBy(p => p["status"]).sort(p => p["status"], 'desc')) {
    dv.header(4, group.key);
    dv.table(["Name", "Goal", "Status"],
        group.rows
            .sort(k => k["category"], 'desc')
            .map(k => [dv.func.link(k.file.path, k.file.name), k["goal"], k["status"]]))
}

I want to display all my project associated with ā€œScutumā€, which is the name of clientā€™s brand. And I separate my work log with my notes by putting them in a folder called ā€œProjectā€. So I use .where() in the for loop to filter other projects in ā€œProjectā€ folder. So far so good.

I record the day I finished that project in the field ā€œstatusā€ and I tried to group them in an order that ā€œIn Progressā€ comes first, and then dates. I used the .sort(p => p[ā€œstatusā€]) to achieve the outcome. However, it turns out to be reverse to what I want. So I tried .sort(p => p[ā€œstatusā€], ā€˜descā€™), but the outcome didnā€™t change and I canā€™t figure out why.

Unfortunately, there is another small problem about the display of my field ā€œstatusā€. I recorded the date in YYYY-MM-DD, but it becomes ā€œSeptember 10, 2021ā€ and the table gets very crowded. Is there a way to solve this problem?

1 Like

@LinGaNinJa Regarding the sorting issue, maybe you can try replacing the quoted code with the following?
.sort(group => group.key, 'desc')

Regarding the date format, I remembered something like the following has been used in a post. Maybe the following can be put before your code:

var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }
1 Like

Hello, @Moonbase59

Is it possible to combine the outlinks and inlinks in one query?

This doesnā€™t workā€¦but I donā€™t understand why it doesnā€™t.

```dataview
LIST 
FROM ([[#]]) AND outgoing([[#]])
WHERE file.name != this.file.name
WHERE file.name !="zettelkasten"
SORT file.name ASC
```

Thanks

Angel

Sorry, @Moonbase59

I was not thinking straight!!

Fixed it. OR not AND:


```dataview
LIST 
FROM ([[#]]) OR outgoing([[#]])
WHERE file.name != this.file.name
WHERE file.name !="zettelkasten"
SORT file.name ASC
```

Angel

1 Like

Youā€™re amazing! Both solutions work perfectly! Iā€™m really happy it works. Really appreciate your help.

Here is the final result. Looks so beautiful.

And here is the revised code.

for (let group of dv.pages('"Project"').where(p => "goal" in p && (p["brand"] == "Scutum")).groupBy(p => p["status"]).sort(group => group.key, 'desc')) {
    dv.header(3, group.key);
    dv.table(["Name", "Goal", "Status"],
        group.rows
            .sort(k => k["category"], 'desc')
            .map(k => [dv.func.link(k.file.path, k.file.name), k["goal"], k["status"]]))
}
5 Likes

This is so insanely usefull that I canā€™t even express how cool and usefull I find it. Thank you!

2 Likes

I would add also this:

WHERE file.name != this.file.name

And this:

Projects due today or within a week from today

TABLE tags, deadline
FROM ""
WHERE deadline - date({{date:YYYY-MM-DD}}T23:59) <= dur(7 days)
SORT deadline ASC
1 Like

I have YAML in the form of this


date:
array:

  • detail1: ā€œAā€
  • detail2: ā€œB1ā€
  • detail1: ā€œAā€
  • detail2: ā€œB2ā€

I am trying to have a table set up with the columns date, detail1, detail2 but I am not making any progress

The closest I can get is this query

table array.detail1, array.detail2

But there are annoying space consuming bullet points on my preview. I want a flat inventory like spreadsheet to be rendered

Like this?

A CSS snippet can suppress the bullets:

/* dataview lists */ 

.dataview-result-list-root-ul 
{
    padding: 0em !important;
    margin: 0em !important;
    list-style-type: none !important;
}

Angel

Can you please give full the dataview query? I have never used css before, I tried copy pasting that code in various intuitive places and couldnā€™t get desired results

Apologies. Only just seen your message.

The full dataview query is in the post above, localised to query files in my vaultā€™s inbox.

The CSS isnā€™t part of the query; it is part of the styling used in the preview pane / output.

See the help directory for adding CSS snippets:

Angel

EDIT: the post below has a small sample CSS snippet and details about how to enable it. You could, perhaps, use it to see how CSS in Obsidian works. It is non-destructive and easily removed.

1 Like

Hi Angel I got up to speed with css snippets today and implemented your example. The issue for me is that the bullet points arenā€™t the problem as much as the space they take up. Is it possible for the example table to only have two rows rather than the four they currently occupy?

UPDATE: My bad, I borked. I missed the fact that YAML demands the metadata section to be at the very top. However, I have two problems with dataview.

The minor one is that the following doesnā€™t work for me:

TASK
FROM "tasks"
WHERE (due = date(today)) AND !completed

As you might have guessed, Iā€™m trying to show all non-completed tasks for Today. It returns zero results.

However, my major problem, that Iā€™ve also mentioned below, is that dataview doesnā€™t work for me at-all on Android. Is it compatible only with the desktop version of Obsidian? If not, any ideas how to troubleshoot/fix the problem?

Feel free to ignore everything below. Iā€™m leaving it here for anyone who wants to laugh at my absent-mindedness.


For some reason Iā€™m not able to make the boolean logic work with dataview in my setup. Iā€™d appreciate some help, since Iā€™ve already spent hours trying to solve the problem and failing.

Iā€™m trying a task management setup where Iā€™ll keep all task-related notes in a folder (named ā€œtasksā€, in Obsidian Vaultā€™s root). Then, I want to ā€œpullā€ all tasks from there and have them listed in a single note, named ā€œ010_Tasksā€. My goal is to have this page, with all my tasks, easily accessible on both my PC and Android smartphone.

Each note with tasks might contain one or multiple tasks. Its structure goes like this:

# Title Like X-Project Tasks
%%
- - -
**Link:** [[Main_Project_Page]]
**Tags:** #maintag/subtag
**Time:** 15:30 Friday, 01-10-21
**Date:** 2021-10-02

**Notes:** 
Anything goes here...
- - -
%%

- [ ] Task 1
- [ ] Task 2
- [ ] Maybe a 3rd one, too!

My first problemā€™s on the PC. Iā€™m trying to create some dataview rules that will pull data from all files in the same folder (ā€œtasksā€), but only present the tasks that match a particular tag. My latest failed attempt is this:

TASK
FROM "tasks"
WHERE Tags = "#maintag/subtag"

ā€¦and, ideally, there should also be a ā€œ!completedā€ somewhere, to hide completed tasks. I havenā€™t even reached that point yet. The output from the above shows nothing. Iā€™ve tried enclosing the Tags = ā€œ#maintag/subtagā€ in parentheses. Nothing. What gives?

Also, on mobile itā€™s even worse: dataview seems to not be working at all. A plainā€¦

TASK FROM "tasks" WHERE !completed

ā€¦that does work on my desktop PC shows nothing on my smartphone.

Soā€¦ Any ideas on what Iā€™m doing wrong? Iā€™m floored by what youā€™ve all achieved, and I canā€™t even proceed to the first step!

Hi all,

I am new to Obsidian and dataview.
I am currently investigating using dataviewjs to extract the notes contains a certain string in a field.
For example, I have to extract all the notes with Name contains string ā€œJohnā€.
It might be Name :: John 123/ Name :: John abc/ Name :: Johnny

I am currently using

dv.list(dv.pages("").where(k => k.name.includes("John")))

But it prompted me the error:
Evaluation Error: TypeError: Cannot read property ā€˜includesā€™ of undefined at eval

May I have your help on this?
Thank You so much