Things I have tried
Hi am new to obsidian “Trying to figure out Js too” Amazing how much you can do with Dataview also THANK YOU! in advance.
What I want to do is convert this
TASK FROM #Todo
WHERE contains(tags, "#Todo") AND !completed
SORT file.mtime DESC
To my best representation of it in JS “But I think I failed miserably ”
$=dv.taskList(dv.pages('').file.tasks .where(t => t.text.includes("#Todo")).sort(f=>f.file.mtime.ts,"desc").limit(5))
Also, I’ll like to keep dv.pages(‘’) in the JS version as that would help me do more crazy stuff in my dashboard.
I could not Edit my Post so here is an edit the Js version is supposed to be like this
$=dv.taskList(dv.pages('').file.tasks .where(t => t.text.includes("#Todo")).sort(f=>f.task.mtime,"desc").limit(4))
Now the problems with my Js code:
- it does not Take away completed Task
- it also gives me this weird heading
I’ll like both of these things in the js versions too.
If you call
dv.taskList( ... , false) you loose the heading, and to loose the completed fields, you just need to add that to your where clause.
.where(t => t.text.includes("#Todo") && !t.completed)
Something like that, should do the trick.
Main problem is related with the
Tasks query in JS doesn’t works as in DQL. In DQL it works at same time in both levels: page level and task level. That’s why you can sort by page level data (file.mtime).
But in js each step downs the level… For example: in
dv.pages() you’re in page level, but after
dv.pages().file.tasks you’re in tasks level… From this moment you can’t target a page level data in normal way. That’s why
.sort(f=>f.file.mtime.ts,"desc") at the end of the code doesn’t works.
And the default
group by file link add an extra problem… I still don’t know how to solve the sort inside this default behavior).
But if you don’t want the headers (using
false as mentioned by @holroy), then it’s more easy to solve.
The most easy way is doing the sort at the page level before “jump” to tasks level.
$=dv.taskList(dv.pages().sort(p => p.file.mtime, 'desc').file.tasks.where(t => t.tags.includes("#Todo") && !t.completed).limit(5), false)
Wow, That does make sense I used
.sort(f=>f.task.mtime,"desc") which fixed the sort issue but your way is much cleaner and
false by @ glory solves the headache of the heading
Thank you Both
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.