You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Queries/Line Continuations.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -42,7 +42,7 @@ Explanation of this Tasks code block query:
42
42
```
43
43
<!-- endSnippet -->
44
44
45
-
This facility will be helpful for long [[Combining Filters]], [[Custom Filters]], and [[Custom Grouping]] lines, and other queries that may be difficult to read on one line.
45
+
This facility will be helpful for long [[Combining Filters]], [[Custom Sorting]], and [[Custom Grouping]] lines, and other queries that may be difficult to read on one line.
46
46
47
47
There are some more realistic examples towards the end of the [[Grouping#Due Date|Due date custom grouping examples]].
Copy file name to clipboardExpand all lines: docs/Queries/Sorting.md
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ publish: true
13
13
This page is long. Here are some links to the main sections:
14
14
15
15
-[[#Default sort order]]
16
+
-[[#Custom Sorting]]
16
17
-[[#Sort by Task Statuses]]
17
18
-[[#Sort by Dates in Tasks]]
18
19
-[[#Sort by Other Task Properties]]
@@ -51,7 +52,16 @@ However, any `sort by` instructions in queries take precedence over these defaul
51
52
52
53
## Custom Sorting
53
54
54
-
==TODO Populate this section==
55
+
> [!released]
56
+
> `sort by function` was introduced in Tasks X.Y.Z.
57
+
58
+
Tasks provides many built-in sorting options, but sometimes they don't quite do what is wanted by all users.
59
+
60
+
Now Tasks has a powerful mechanism for you to create your own **custom sort orders**, offering incredible flexibility.
61
+
62
+
There are many examples of the custom filtering instruction `sort by function` in the documentation below, with explanations, for when the instructions built in to Tasks do not satisfy your preferences.
63
+
64
+
You can find out more about this very powerful facility in [[Custom Sorting]].
55
65
56
66
## Sort by Task Statuses
57
67
@@ -61,6 +71,9 @@ For more information, including adding your own customised statuses, see [[Statu
61
71
62
72
-`sort by status` (done or todo)
63
73
74
+
> [!Tip]
75
+
> `sort by status.type` gives a much more useful sort order than `sort by status`. See [[#Status Type#]] below.
76
+
64
77
Since Tasks X.Y.Z, **[[Custom Sorting|custom sorting]] by status** is now possible.
65
78
66
79
<!-- placeholder to force blank line before included text --><!-- include: CustomSortingExamples.test.other_properties_task.isDone_docs.approved.md -->
| Strings | Example: `sort by function task.originalMarkdown`<br>Tasks are sorted alphabetically by the string key values. The sort is case-sensitive. It is aware of numbers and sorts them logically. |
60
+
| Numbers | Example: `sort by function task.description.length`<br>Numbers are sorted in ascending order. The lower the number, the earlier the task is sorted. |
61
+
| Boolean values: `true` and `false`| Example: `sort by function task.status.name.includes('!!')` <br>Tasks with sort key `true` sort before ones with `false`. |
62
+
|`TasksDate` and `Moment` objects | Example: `sort by function task.created`<br>See [[Sorting#How dates are sorted\|How dates are sorted]]. |
63
+
|`null`|`null` sorts after valid `TasksDate` and `Moment` objects, and before all other sort key values. |
66
64
67
65
The `expression` can:
68
66
@@ -71,19 +69,15 @@ The `expression` can:
71
69
72
70
The `expression` must:
73
71
74
-
==TODO Update this==
75
-
76
-
- use properties on a given task, such as `task.description`, `task.status.name`
77
-
- See the reference page [[Task Properties]] for all the available properties
78
-
- return one of:
79
-
- either a single value of any type that can be converted to string
80
-
- or an array of values (in which case, the task will be displayed multiple times, once under each heading generated from the array)
72
+
- use properties on a given task, such as `task.description`, `task.status.name`.
73
+
- See the reference page [[Task Properties]] for all the available properties.
74
+
- return one of types of values listed in the table above.
81
75
82
76
## Example custom sorts
83
77
84
78
Below are some examples to give a flavour of what can be done with custom sorts.
85
79
86
-
You can find many more examples by searching for `sort by function` in the [[Sorting]] page.
80
+
You can find some more examples by searching for `sort by function` in the [[Sorting]] page.
87
81
88
82
### Text property examples
89
83
@@ -115,6 +109,11 @@ sort by function \
115
109
116
110
### Date property examples
117
111
112
+
Useful sections:
113
+
114
+
-[[Task Properties#Values in TasksDate Properties|Values in TasksDate Properties]]
115
+
-[[Sorting#How dates are sorted|How dates are sorted]]
116
+
118
117
<!-- placeholder to force blank line before included text --><!-- include: CustomSortingExamples.test.dates_task.due_docs.approved.md -->
119
118
120
119
```javascript
@@ -140,6 +139,10 @@ sort by function reverse task.urgency
140
139
141
140
### File property examples
142
141
142
+
Useful sections:
143
+
144
+
- [[Task Properties#Values for File Properties|Values for File Properties]]
145
+
143
146
<!-- placeholder to force blank line before included text --><!-- include: CustomSortingExamples.test.file_properties_task.file.folder_docs.approved.md -->
144
147
145
148
```javascript
@@ -159,28 +162,11 @@ sort by function task.file.path === query.file.path
159
162
160
163
## Troubleshooting
161
164
162
-
> [!Warning]
163
-
> Currently most types of error in function expressions are only detected when the search runs.
165
+
> [!Tip]
166
+
> To test the values obtained from your sort key, replace `sort by` with `group by`. The generated group headings provide a sort of "debugger" to show expression values.
164
167
>
165
-
> This means that error messages are displayed in the sort headings, when results are viewed.
166
-
>
167
-
> In a future release, we plan to show errors in formulae when the query block is being read.
168
-
169
-
### Syntax error
168
+
> However, be aware that whilst `group by` expressions can return arrays of values, `sort by` does not yet support arrays.
170
169
171
-
The following example gives an error:
172
-
173
-
````text
174
-
```tasks
175
-
sort by function hello
176
-
```
177
-
````
178
-
179
-
gives this heading name:
180
-
181
-
```text
182
-
##### Error: Failed calculating expression "hello". The error message was: hello is not defined
183
-
```
170
+
## Limitations of Custom Sorting
184
171
185
-
> [!todo]
186
-
> Do syntax-error checking when parsing the instruction
172
+
- Arrays cannot yet be used as sort keys, as we have not figured out the appropriate way to sort arrays of different lengths.
0 commit comments