What is the exact syntax (including the dataview part) to make this work?
Also, do we need to change the default date format?
What is the exact syntax (including the dataview part) to make this work?
Also, do we need to change the default date format?
Just put the code shown into a dataviewjs
code block (instead of dataview
).
No. But there are cases where it is extremely useful.
Be aware that the code shown by @AutonomyGaps will pick up any file in the vault that has something in its title that looks like a date to Dataview. If you donāt want that, you can specify a folder name inside the dv.pages()
line, in the form of dv.pages('"Daily Notes"')
.
Docs on Dataview here: https://blacksmithgu.github.io/obsidian-dataview/docs/intro
I am getting this error message:
Evaluation Error: TypeError: Cannot read property āisValidā of undefined
at DateTime.equals (eval at (app://obsidian.md/app.js:1:1153594), :7732:34)
at eval (eval at (eval at (app://obsidian.md/app.js:1:1153594)), :9:27)
at Array.filter ()
at Proxy.where (eval at
Hi, this is great.
Iām trying to do a similar database but for research purposes.
In the image below, a database of images.
I tried to add the image-preview in the table using the HTML format in the frontmatter or in inline field (something like <img src="file:///Users/......">
) and it works⦠But the table turns unstable and when it does an automatic refresh the table presents some glitches (a kind of āshakesā, as a graphical issue).
Now Iāll try to use your format ("")
and verify if the graphical issues gone away. One question: what kind of link you put in ācoverā property?
Didnāt try @AutonomyGapsā new code, but let me check in my vault. What version of Dataview are you using, and which version of Obsidian?
EDIT: RESULTS
I found that I got the same error as you, had to leave the note and reopen it a few times and wait some minutes until it worked. The error occurs when file.day
canāt be populated (because the file has no recognized date in the title, and no date: YYYY-MM-DD
frontmatter field).
I have this now, and it works (the file is also called 2021-05-23 Test DataviewJS AutonomyGaps
, to provide a date to file.day
):
# 2021-05-23 Test DataviewJS AutonomyGaps
file.day: `=this.file.day`
file.mday: `=this.file.mday`
file.cday `=this.file.cday`
```dataviewjs
// default dateformat in case itās forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }
dv.table(["File", "Last Modified", "Date Created"],
dv.pages()
.where(p => p.file.mday.equals(dv.current().file.day) || p.file.cday.equals(dv.current().file.day))
.sort(p => p.file.mtime, 'asc')
.map(p => [
p.file.link,
moment(p.file.mtime.toString()).format(dateformat),
moment(p.file.ctime.toString()).format(dateformat),
])
);
ā```
(Note the last line ``` is faked for the forumāremove it if copying, and use real 3 backticks.)
Result:
all the latest versions
Saying ālatestā is always bad if people come here months after ⦠using numbers is preferred.
Btw, I used Obsidian 0.12.3 and Dataview 0.3.9 for this test.
@yalcin @AutonomyGaps It seems Dataview sometimes doesnāt āseeā the latest, probably due to Obsidianās rather effective caching. In my case, I sometimes had to wait a few minutes, or close & reopen Obsidian until all was seen again (especially when renaming the note that has the code).
To make it more user-friendly, even if the current note doesnāt have a valid file.day
, you could change the code like this:
// default dateformat in case itās forgotten in front matter
var dateformat = "YYYY-MM-DD";
if (dv.current().dateformat) { dateformat = dv.current().dateformat; }
dv.table(["File", "Last Modified", "Date Created"],
dv.pages()
.where(p => dv.current().file.day && (p.file.mday.equals(dv.current().file.day) || p.file.cday.equals(dv.current().file.day)))
.sort(p => p.file.mtime, 'asc')
.map(p => [
p.file.link,
moment(p.file.mtime.toString()).format(dateformat),
moment(p.file.ctime.toString()).format(dateformat),
])
);
Study the where
clause: We only do it if file.day is valid.
On a note that has no date, you would now of course also get no results. But also no error message. (I removed the date from the noteās title for this test):
I just use a regular link in the cover property. I copy the image URL from Amazon and stick it in there.
Thanks so much for your fine-tuning of this!
Thanks. Regarding the mentioned graphic issues, this seems to indicate that there is a difference between links to local files and URL links.
I have a simple table to collect my journal entries related to a given book. Iām trying to have one of the columns show a link to the heading where I wrote the entry:
table Chapters, file.link+"#Reading:: The Lost Symbol" as Link from #my/journal where Reading="The Lost Symbol" sort file.ctime asc
And it results in this
Instead of resulting in a [[2021-05-23#Reading The Lost Symbol]] link, it gives me a separate text ([[2021-05-23]] reading ā¦)
Iām not very literate in codes, but Iāve been studying the documentation to see if thereās a way to achieve this. Do you guys know if itās even possible?
Nevermind: found the answer here: Dataview plugin snippet showcase - #158 by jyrodgers
I want to do this (extract data from a field for use in the query) as well.
Context: I want to make a query that shows people I havenāt contacted in a defined amount of time. The people have a field ādesired contact frequencyā and in it is ā2 weeksā or ā2 monthsā, whatever. The query:
TABLE
context, file.mday AS "Last Contact"
FROM "3 - Resources/People"
WHERE desired-contact-frequency AND file.cday <= date(now) - dur(1 week)
SORT file.mday ASC
^ Works
\/ Doesnāt work:
TABLE
context, file.mday AS "Last Contact"
FROM "3 - Resources/People"
WHERE desired-contact-frequency AND file.cday <= date(now) - dur(desired-contact-frequency)
SORT file.mday ASC
Thereās probably a way to do this in the js version, but 1) Iām not capable of that and 2) it seems like if thereās a way to access ādesired-contact-frequencyā this is a much simpler format.
Instead of this, could you try,
"[[" + file.name + "#Reading:: The Lost Symbol]]"
You can even add alias to the link if it gets long like,
"[[" + file.name + "#Reading:: The Lost Symbol|The Lost Symbol]]"
Oh! It worked. Thatās amazing, thanks a bunch, Rishi.
Hereās a snippet I use to make lists render as comma separated items instead of bullet points:
dv.table(
['File', 'Connections'],
dv.pages('[[Foo]]').map((page) => {
return [
`[[${page.file.name}]]`,
page.file.outlinks
.reduce((acc, outlink) => {
acc += `[[${outlink.path.replace(/\.md$/, '')}]], `;
return acc;
}, '')
.trim()
.replace(/,$/, '')
];
})
);
Now this is very close to:
Table file.outlinks as Connections
From [[Foo]]
Except that the list renders differently. Obviously that is a lot of code to write just for a format change, but I like how the table looks quite a bit more with that.
Hereās a slightly cleaner version with .map()
:
dv.table(
['File', 'Connections'],
dv.pages('[[Foo]]').map((page) => {
return [
`[[${page.file.name}]]`,
page.file.outlinks
.map((link) => {
return `[[${link.path.replace(/\.md$/, '')}]]`;
})
.join(', ')
];
})
);
But all are superseded by @Rishiās suggestion of the undocumented join()
:
This should make them identical,
Table join(file.outlinks, ", ") as Connections
From [[Foo]]
This function needs to be added to the docs still but you can find the relevant discussion on Github.
Awesome!
Hi everyone!
Iād like to implement a GAO (Got Aware Of) tracking system.
For any book or website, one note containing several records of type
GAO:
When: [[2021-06-02]]
What: [[Topic-name]]
Then, in each daily note, something like
```dataview
LIST GAO.What
FROM "Resources"
WHERE GAO.When = this.file.name
But this, unfortunately, doesnāt workā¦
Is this possible somehow? Any idea?
Thanks in advance.
ā
silvio
Could you try,
WHERE GAO.When = this.file.link