Please note that I am NOT an expert in JS. These are what have worked for me, but I would not be surprised if there was a more optimal way to do this. However, I am here to help how I can. ALSO, one note about my DataviewJS style - I prefer to create a DV DataArray outside of a dv.table() call - I find that it keeps it a tad cleaner, and I am able to add more functionality that way.
Comparing dates can be a little tricky from my experience. If you are using the standard ISO format in your DV fields (e.g. 2021-11-15) as I am:
// Below line of code is outside of the dv.pages() call
let today = DateTime.local().toISODate();
// I like to create my DV DataArrays outside of the dv.table call
let taskList = dv.pages("#tasks")
.filter(t => t["due-date"] !== null)
.filter(t => dv.date(t["due-date"]).toISODate() <= today);
To my knowledge, I don’t think you can have two different DV sources in the FROM command. To solve this use case, I just add another filter statement to remove in the pages query:
let projectList = dv.pages("#projects")
.filter(p => !p.file.folder.contains("INSERT FOLDER NAME HERE]"));
For Next Date, I don’t have anything with this specific use case in my vault, but would probably involve using Luxon Duration. Please note I haven’t actually tested the implementation below, this is just a quick idea I cobbled together.
// All of your code above
.map(t =>
// More Code - rough NEXT DATE QUERY below
t["recur-length"] ? dv.date(t["do-date"]).plus({ days: t["recur-length"] }).toISODate() : " ",
// Rest of your code
My full button code (should have probs included it in other thread):
My friend @asauceda94 - noted… you’re not an expert, but you’ve definitely got skills and generosity - many thanks for your reply!
My progress: I have played around with your JS snippets, I have started a coding course to help, and I have tried really, really hard haha … But I feel like a toddler playing with a 1000 piece jigsaw puzzle.
Maybe I’ll have the skills someday in the future. It might be the instructional to see your code as a complete block, rather than walking me through step by step. What do you think?
But specifically I am having trouble with
Insert Date Button code - I don’t know what goes into .map(t => at buttonMaker('FIELD', 'INSERTED TEXT', t.file.path)
despite your explanations about DataviewJS style and arrays being outside of dv.table() call, I can’t find the right place for the “let” functions and filters. When I put them
Considering that daily notes name has the format 2021-11-23, the following snippet lists tasks from previous daily notes and future 3 days, excluding the current day.
Sure !
The first line is the header, like Paper, Title, Year etc…
All my files are in the folder Zettelkasten.
The line "[[" + b.file.name + "|" + (b.file.aliases[1] || b.file.aliases[0]) + "]]", means to create a link for the first column, you can skip it.
The lines
Howdy again @dryice ! Sorry for the delay - holidays and all.
Let’s see if I can help! I’ll paste the first code block below, but first, a disclaimer - you should never, EVER, blindly paste code into dataviewjs if you don’t understand it. Bad actors could utilize it to wreak havoc on your system. This isn’t that but good practice moving forward
You might want to read the MetaEdit docs to understand a little more thoroughly, but the ‘FIELD’ is the DataView/YAML field that you want to update (for instance, ‘completion-date’ is a YAML field on my Task notes.
Hopefully the code block above helps, but if it doesn’t, please let me know! I’m not sure I quite understand the issue you might be having here.
Is there anyone who know how to embed the results from dataviewjs?
```dataviewjs
let pages = dv.pages("#math").where(b => b.difficulty >= 1);
for (let group of pages.groupBy(b => b.material)) {
dv.header(group.key);
dv.list(group.rows.file.link);
}
Now, I got the list of links to the files.
file1
file2
file3
What I want to get is like these
![[file1]]
![[file2]]
![[file3]]
Thnak you in advance.
To make this work, each daily journal entry needs frontmatter that looks like this:
---
habits:
habit_1:
habit_2:
habit_3:
---
To use this frontmatter everyday, you can enable the Templates core plugin in Settings > Core plugins > Templates.
Then go to the options in Settings > Plugin options > Templates, and choose your folder location. In that folder, create a file called Daily_note where you will add the above frontmatter.
Then in Settings > Plugin options > Daily notes, update your Template File Location to the above your_template_folder/Daily_note.md. Now whenever you create a daily note, it will contain that frontmatter.
To see the table view of all your habits like in the first image, you can copy this snippet. You need to get the raw snippet, so if you’re not familiar with how that works, just use this link
In that snippet, the first section tells you what you need to change in order to match your system. Most important, habit_names have to match the exact names of the habits in your frontmatter. And daily_journal_loc needs to point to the folder where your journals are located.
Appears for a few seconds and then disappears again. I’m wondering whether there’s a bug. I had a look through the forum and noticed this thread that raised there was an issue with the Obsidian Plugin API not rendering embeddings… could this be the issue?
I wondered whether maybe the image size was an issue so I tried reducing the image size with the 200
Can someone help with this ‘Birthday’ issue please. It used to render the age in whole years of a person on their next birthday, along with their birthDate. Recently however, the age began rendering up to 14 decimal points – odd.
Hi,
I am new to Obsidian and I really find dataview to be very helpful. Even more so with js added to it. I am however not the strongest coder so I run into a bit of an issue.
What I want to achieve is a list of all my tasks on all pages sorted by the first tag in each task. All my tasks starts with a tag.
So I started with listing all not completed task.
Part two is a bit more tricky, I have found.
I have managed to make it a single list(without headings) but I think that it is due to either a bug or something I dont understand. And it is not sorted by the tag.
This is the code for that(dataview obviously):
TASK WHERE !completed GROUP BY file.tag
If i add an “s”(file.tags) to the last part of this query it will list all tasks in same file with Tags as heading.
Tags in task text aren’t parsed as tags. They’re just content (obsidian-tasks understands tags in the context of tasks, but dataviewdoes not and Obsidian does not). The tags you see in the latter example are the file’s tags, not the tags attached to the task. Since the tag is at the beginning of the text, what you actually want is to sort alphabetically. You can accomplish that with this:
// 1. Let's gather all relevant pages
const pages =
dv.pages('"_tmp/20210922 test for sumant28/Life"')
.filter(page => page.file.name.includes("test note"));
// 2. Now let's transform from thing per date (we have single page for each date) into thing per purchase (we want to have as many rows in a table as all purchases extracted from all pages)
const purchases = [];
pages.forEach(page => {
page.purchases.forEach(purchase => {
purchases.push({
file: page.file,
date: page.date,
store: purchase.store,
item: purchase.item,
comments: purchase.comments,
});
});
});
// 3. Let's sort it by date, newest first (note "-" before "purchase.date")
purchases.sort(purchase => -purchase.date);
// 4. And let's print a table of those purchases
dv.table(
[
"File",
"store",
"item",
],
purchases.map(purchase => [
purchase.file.link,
purchase.store,
purchase.item,
])
);
I had logged dozens of entries making the resulting table too unwieldy. I already have pages set up for each store in Obsidian which is a file link in the table using this syntax “[[store]]”. I want to display a filtered DataviewJS with purchases only from that store that goes on the bottom of every store file in my vault. I figured out how to filter the table using an extra int field called rating but I want to filter instead based on the .includes function but whenever I try to do this I get the error message saying purchases.store.includes is not a function.