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/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. |
60
64
61
65
The `expression` can:
62
66
@@ -65,19 +69,15 @@ The `expression` can:
65
69
66
70
The `expression` must:
67
71
68
-
==TODO Update this==
69
-
70
-
- use properties on a given task, such as `task.description`, `task.status.name`
71
-
- See the reference page [[Task Properties]] for all the available properties
72
-
- return one of:
73
-
- either a single value of any type that can be converted to string
74
-
- 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.
75
75
76
76
## Example custom sorts
77
77
78
78
Below are some examples to give a flavour of what can be done with custom sorts.
79
79
80
-
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.
81
81
82
82
### Text property examples
83
83
@@ -109,6 +109,11 @@ sort by function \
109
109
110
110
### Date property examples
111
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
+
112
117
<!-- placeholder to force blank line before included text --><!-- include: CustomSortingExamples.test.dates_task.due_docs.approved.md -->
113
118
114
119
```javascript
@@ -134,6 +139,10 @@ sort by function reverse task.urgency
134
139
135
140
### File property examples
136
141
142
+
Useful sections:
143
+
144
+
- [[Task Properties#Values for File Properties|Values for File Properties]]
145
+
137
146
<!-- placeholder to force blank line before included text --><!-- include: CustomSortingExamples.test.file_properties_task.file.folder_docs.approved.md -->
138
147
139
148
```javascript
@@ -153,28 +162,11 @@ sort by function task.file.path === query.file.path
153
162
154
163
## Troubleshooting
155
164
156
-
> [!Warning]
157
-
> Currently most types of error in function expressions are only detected when the search runs.
158
-
>
159
-
> This means that error messages are displayed in the sort headings, when results are viewed.
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.
160
167
>
161
-
> In a future release, we plan to show errors in formulae when the query block is being read.
168
+
> However, be aware that whilst `group by` expressions can return arrays of values, `sort by` does not yet support arrays.
162
169
163
-
### Syntax error
164
-
165
-
The following example gives an error:
166
-
167
-
````text
168
-
```tasks
169
-
sort by function hello
170
-
```
171
-
````
172
-
173
-
gives this heading name:
174
-
175
-
```text
176
-
##### Error: Failed calculating expression "hello". The error message was: hello is not defined
177
-
```
170
+
## Limitations of Custom Sorting
178
171
179
-
> [!todo]
180
-
> 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