Dataviewjs, sort tasks by page name

Hello,

I’m new to Obsidian and I really like the flexibility. But this can be sometimes overwhelming. At the moment I try to configure Obsidian the way I want to use it by reading a lot of blog posts, listening to YoutTube videos and copy&past config snippets.

At the moment I struggle with this one:

dataviewjs
dv.taskList(dv.pages('-"Templates"').file.tasks
.where(t => !t.completed).sort())

It gives my all open tasks grouped by the page name. But the order of the page seems to be random. I would like to order the output by the name of the page (A-Z). Adding the “.sort()” was my first try. While it doesn’t create a error, the output is still the same.

Any idea how to do it.

Trying to do the same here - were you able to figure it out?

Topic

Summary
  • How to sort the output by the name of the page in ascending order?

Test

Summary
  • dataview: v0.5.46

Input

Summary

dictionary files:

  • Location: “100_Project/01_dataviewjs/01_by_example/Q83_taskList/Q83_test_data”

folder: 04_tasks

  • filename : dic_19810401
  • file.ctime: “1981-04-01T19:30:50”
---
Date: 1981-04-01
---
#Project/P04

## input
### tasks
- [ ] 1981-04-01 add this feature_a #Test/d01 [[Note P]] , [[Note Q]]
- [ ] 1981-04-02 add this feature_b #Test/d02  [[Note P]]
- [ ] 1981-04-03 add this feature_c  [[Note Q]]
- [ ] 1981-04-04 add this feature_d #Test/d04 



  • filename : dic_19810415
  • file.ctime: “1981-04-15T19:30:50”
---
Date: 1981-04-15
---
#Project/P04

## input
### Question A
- [ ] [type:: "food"] [desc:: "breakfast"] [cost:: 100] #Test/d01 [[Note P]] , [[Note Q]]
- [ ] [type:: "food"] [desc:: "breakfast"] [cost:: 200] #Test/d02  [[Note P]]



  • filename : dic_19810430
  • file.ctime: “1981-04-30T19:30:50”
---
Date: 1981-04-30
---
#Project/P04

## input
### Question B
- [ ] [type:: "food"] [desc:: "dinner"] [cost:: 300] [[Note Q]]
- [x] [type:: "food"] [desc:: "dinner"] [cost:: 400] #Test/d04
- [ ] (type:: "food") (desc:: "dinner") (cost:: 500) #Test/d05
    - [ ] C1
        - [ ] C2
            - [ ] C3



DVJS10_use_fTasks_filter_by_uncompleted_tasks_and_taskList

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS10
_use_fTasks
_filter_by_uncompleted_tasks
_and_taskList
file.tasks no 1.To filter pages by page.file.ctime
2.To sort pages by page.file.name in ascending order
3.To filter tasks by an uncompleted task
4.To display the result as a taskList [with the desired structure]

Notes

Summary

Q1: How to sort the output by the name of the page in ascending order?

Summary_Q1
```js
dv.taskList(
    dv
        .pages('-"Templates"')
        .file.tasks.where((t) => !t.completed)
        .sort()
);
```

A1:

```js
dv.taskList(
    dv
        .pages('-"Templates"')
        .sort((page) => page.file.name, "asc")
        .file.tasks.where((t) => !t.completed)
);
```

code DVJS10_use_fTasks_filter_by_uncompleted_tasks_and_taskList

Summary_code
title: DVJS10_use_fTasks_filter_by_uncompleted_tasks_and_taskList =>1.To filter `pages` by `page.file.ctime` 2.To sort `pages` by `page.file.name` in ascending order 3.To filter `tasks` by an uncompleted task 4.To display the result as a taskList [with the desired structure]
collapse: close
icon: 
color: 
```dataviewjs
// M11. define pages: gather relevant pages
// WHERE_CASE_11: To filter `pages` by `page.file.ctime` 
// SORT_CASE_12 : To sort `pages` by `page.file.name` in ascending order
// #####################################################################
let pages = dv
    .pages(
        '"100_Project/01_dataviewjs/01_by_example/Q83_taskList/Q83_test_data"'
    )
    .where(
        (page) =>
            page.file.ctime >= dv.date("1981-03-01T00:00:00") &&
            page.file.ctime <= dv.date("1981-09-30T23:59:59")
    )
    .sort((page) => page.file.name, "asc");


// M21.define tasks: gather uncompleted tasks
// WHERE_CASE_11: To filter `tasks` by an uncompleted task
// (comments)SORT_CASE_12 : To sort `tasks` by `t.text` in descending order
// #####################################################################
let tasks = pages.file.tasks
    .where((t) => !t.completed);
    //.sort((t) => t.text, "desc");


// M31.Output tasks: [with the desired structure]
// #####################################################################
dv.taskList(tasks, true);




Screenshots(DVJS10)


I found out how to do it sorting by page.file.ctime, which you can adapt for your own purposes of page name:

Didn’t work for me but Jillard in the discord provided

dv.taskList(dv
	.pages()
	.sort((page) => page.file.ctime, "desc")
	.file.tasks
	.where(t => !t.completed && t.text.includes("<inline_search_term>"))
	.groupBy(g => dv.page(g.link.path).file.link)
	.sort(s => dv.page(s.key).file.ctime, "desc")
	, false
)

(replace inline_search_term)

where the key was adding to the tasks object:

.groupBy(g => dv.page(g.link.path).file.link)
	.sort(s => dv.page(s.key).file.ctime, "desc")
	, false

since it seems the original sort is overridden by default