Sorting Dataview JS

Topic

Summary
  • How to list task items in the descending order where the files were created?

Test

Summary
  • dataview: v0.5.46

Input

Summary

dictionary files:

  • Location: “100_Project/01_dataviewjs/01_by_example/Q81_TasksSort/Q81_test_data”

folder: 03

  • filename : dic_19750301
  • file.cday : “2022-11-24”
---
Date: 1975-03-01
---
#Project/P03

- [[Note P]] main task GH
  - [ ] task g
  - [ ] task h
      - [ ] task h1
      - [ ] task h2



folder: 04

  • filename : dic_19750401
  • file.cday : “2022-11-25”
---
Date: 1975-04-01
---
#Project/P04

- [ ] [[Note P]] main task IJ
  - [ ] task i
  - [ ] task j
      - [ ] task j1
      - [ ] task j2



folder: 07_done

  • filename : dic_19750701
  • file.cday : “2022-11-28”
---
Date: 1975-07-01
---
#Project/P07

### main tasks : CASE S1
- [[Note P]] main task GH
  - [x] task g
  - [x] task h
      - [x] task h1
      - [x] task h2



folder: 08_empty

  • filename : dic_19750801
  • file.cday : “2022-11-29”
---
Date: 1975-08-01
---
#Project/P08

## input
### Summary



DQL10_use_fTasks_filter_by_uncompleted_tasks_and_TASK

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_use_fTasks
_filter_by
_uncompleted_tasks
_and_TASK
flattened file.tasks yes 1.To filter by file.name
2.To filter by file.ctime
3.To filter by an uncompleted task
4.To group by header
5.To sort by rows.file.cday in descending order
6.To display the result as a taskList [with the desired structure]

Code DQL10_use_fTasks_filter_by_uncompleted_tasks_and_TASK

Summary_code
title: DQL10_use_fTasks_filter_by_uncompleted_tasks_and_TASK =>1.To filter by file.name 2.To filter by file.ctime 3.To filter by an uncompleted task 4.To group by header 5.To sort by rows.file.cday in descending order 6.To display the result as a taskList [with the desired structure]
collapse: close
icon: 
color: 
```dataview
TASK
FROM "100_Project/01_dataviewjs/01_by_example/Q81_TasksSort/Q81_test_data"

WHERE file.name != "2022-11-27"
WHERE file.ctime >= date("2022-11-20")

WHERE !completed

GROUP BY header
SORT rows.file.cday DESC

```

Screenshots(DQL10)


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 yes 1.To filter by page.file.name and page.file.ctime
2.To filter by an uncompleted task
3.To group by k.header
4.To sort by file.cday in descending order
5.To display the result as a taskList [with the desired structure]

Notes

Summary

Q1: What is the same code as the DVJS10?

Summary_Q1

A1:

Another Example11
title: Another Example11 => 
collapse: close
icon: 
color: 
```dataviewjs
dv.taskList(
    dv
        .pages(
            '"100_Project/01_dataviewjs/01_by_example/Q81_TasksSort/Q81_test_data"'
        )
        .where(
            (page) =>
                page.file.name !== "2022-11-27" &&
                page.file.ctime >= dv.date("2022-11-20")
        )
        .file.tasks.where((t) => !t.completed)
        .groupBy((k) => k.header)
        .sort((k) => dv.page(k.key.path).file.cday, "desc")
);
```

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 by page.file.name and page.file.ctime 2.To filter by an uncompleted task 3.To group by k.header 4.To sort by file.cday in descending order 5.To display the result as a taskList [with the desired structure]
collapse: close
icon: 
color: 
```dataviewjs
// M11. define pages : gather all relevant Tasks
// #####################################################################
let pages = dv
    .pages('"100_Project/01_dataviewjs/01_by_example/Q81_TasksSort/Q81_test_data"')
    .where(
        (page) =>
            page.file.name !== "2022-11-27" &&
            page.file.ctime >= dv.date("2022-11-20")
    );
    //.sort((page) => page.file.cday, "desc");


// M21. define myTasks : gather all relevant Tasks
// #####################################################################
let myTasks = pages.file.tasks
    .where((t) => !t.completed)
    .groupBy((k) => k.header)
    .sort((k) => dv.page(k.key.path).file.cday, "desc");


// M31. output myTasks : 
// #####################################################################
dv.taskList(myTasks);


```

Screenshots(DVJS10):