DataviewJS Snippet Showcase

Btw my error message is “Evaluation Error: TypeError: Cannot read property ‘contains’ of undefined”

1 Like

Hi, does anyone know how to use taskList, but have it not include sub-bullet-points located directly underneath the task? For example, I have tasks that are structured like this:

- [ ] Actual task that I want to appear in taskList
    - Example contextual note I included as sub-bullets
    - Note that these are not tasks / sub-tasks since they lack leading brackets
    - However, taskList still displays them and makes the view too busy

I’ve noticed that those sub-bullet records are stored in the data array with a value for real equaling ‘false’. So I tried to filter for only real == true in the where section, but no luck.

dv.taskList (dv.pages('#tag').file.tasks.where(t => !t.completed && t.real)

Its called “Heatmap Calendar”, search for it on the community plugin list in obsidian

Hi,

I got this code from Eleanor Konik.


//get all md files in vault

const files = app.vault.getMarkdownFiles()

//create an array with the filename and lines that include the desired tag

let arr = files.map(async(file) => {

const content = await app.vault.cachedRead(file)

//turn all the content into an array

let lines = await content.split("\n").filter(line => line.includes("- [?]"))

return ["[["+file.name.split(".")[0]+"]]", lines]

})

//resolve the promises and build the table

Promise.all(arr).then(values => {

console.log(values)

//filter out files without "ad-question" and the note with the dataview script

const exists = values.filter(value => value[1][0] && value[0] != "[[dataviewjs-testing]]")

dv.table(["file", "lines"], exists)

})

I am trying to customise it to show me results only from files tagged #learning. So far no luck. I unsuccessfully tried using dv.pages("#learning").

Can somebody help me, please?

Thanks

You probably need k.file.name.includes rather than just k.name.includes

Dataview and Dataview JS for real novices.

I have tried to find a couple of tutorials out there but have found that the gap between a simple dataview query and the same in dataview JS is quite big. If you are new to coding and just want that little bit extra that DataviewJS gives you but are not that good at coding it can be a real challenge. So I thougt I write a little about my setup(really task focused right now) and give a code examples. Maybe it can help someone else to bridge the gap… :slight_smile:

I write all my notes in a daily pages. Its a real mix of meeting notes, tasks and just good to know things.

I am trying out a system that I found at Steve Boyds page here: How I Use Daily Notes In Obsidian [Wonkish] - by Stowe Boyd.
Instead of using hashtags for tags I create some of my own with the following structure [ø:: ”tag”] where ”tag” is the group I want for this task. if it is a task formyself i would write
’- [ ] [ø:: me] ”text of what should be done”.
If i have a task with a due date it would look like this:
’- [ ] [ø:: me] [due:: 2022-05-16] ”text of what should be done by this date”
Both of these of course without the ’ at the beginning to make it a task in obsidian.

I also asign some tasks with the tag ”today”.
So for my daily template I want to list all my tasks wit a due date.
Next I want all my task that should be done today.

I started in Dataview and this worked but dataview wants to group everything with a header and that is to me not a good way to present it.
So below is dataview and dataviewjs querys for listing all tasks with duedates that are not completed, sorted ascending.

Dataview query for listing all tasks with a due date that is not completed. Grouped by due date ascending
TASK
WHERE !completed
WHERE due
GROUP BY due
SORT due asc
DataviewJS query for listing all tasks with a due date that is not completed. Sorted ascending but not grouped by anything.
dv.taskList(dv.pages().file.tasks .where(t => !t.completed).where(t => t.due).sort(t => t.due, "asc"), false)

I have noticed that even though I enjoy the system of designing my own tags with the ø:: system it also makes it a bit more complicated when trying to achieve things that most likely is a lot easier if I would have stuck to the original hashtag system. But I like the way it looks. :slight_smile:
I know this is really simple compared to everything here but I found it quite hard to get the Dataviewjs query to do what I wanted. Hopefully someone might have use of it.

1 Like

So now to my next challenge and question.

So the first part of my daily template is all task with due dates
After this I do tasks that are not completed and I have marked as today group by ”tag” if I have any.
These tasks looks like this in my files: - [ ] [ø:: idag] ”Any thing I want to fokus on today”
Below is the dataview query I have for this and it works as it should but I dont want the grouping behavior of dataview so I turn to DataviewJS

(idag=today in swedish)

Dataview query for tasks marked as today
TASK
WHERE !completed
WHERE ø = "idag"
GROUP BY ø

However, this dataviewJS is not working. I am pretty sure that that is due to me not quite understanding how I can filter on the ”ø” I use as my tags.

DataviewJS query for tasks marked as today
dv.taskList(dv.pages().file.tasks.where(t => !t.completed).where(t => t.ø(”idag”)), false)

Any suggestions would be helpful. :slight_smile: