There some things to consider in this query, but the main thing causing the result to group together is the missing second parameter to
dv.taskList(..., false). See Codeblock Reference - Dataview
However, let us also address some other issues whilst doing this response.
Hard-coded dates as text?!
I’m hoping this is just for the test purposes, and that you don’t intend to hard-code your dates like in the following line:
.where(t => t.text.includes("2023-01-25"))`
And that given the query resides in a daily note, you’d rather use something using the link as a link, and fetching tasks just linking to the current file.
The sort line
You use the following for sorting purposes:
.sort(t => Date.parse(t.text.replace(/ .*/,'')), 'asc')
Here you replace everything after the space with nothing, so your basically left with the timestamp, which you then try to convert to a date. But a timestamp is not a date, unless it actually gets something like
2023-01-25T in front of it.
And even then, you would have an issue related to timestamps with just single digits as hours. E.g. “2023-01-25T9:00” is not a legal date and timestamp, so it wouldn’t be parsed as such. In other words, your sorting as it stands just sorts on an undefined value, a non-legal date.
To correct this, you could either add in a (random) date in front of the text, like I did here: How to calculate amount of time in dataview query - #4 by holroy
Or, you could also opt for adding the date of the link into it, to make it more “real”. Still, you’d want to tackle the issue with single digits in the hour place, so you could do something like:
t.text.replace(/^([0-9]:)/, "0$1") before the concatenation with the date.
Skip the date parsing, and just sort on the text
I don’t really see the need for doing that date parsing, unless you plan to include multiple dates into the mix, so a simpler solution would be the following:
.where(t => !t.completed)
.where(t => t.text.includes("2023-01-25"))
.sort(t => t.text
.replace(/^ */, "")
Here I’ve not compensated for the hard-coded date in the first
where clause, but I’ve adjusted the sorting. Firstly I just remove any extraneous spaces at the beginning, to level out the playing field if you were sloppy with your spaces one day.
Secondly, I add a zero in front of the single digit (when sorting), to make it sort better. I don’t bother removing the rest of the line, as in most cases it wouldn’t matter. However, if you were to have to activities on the same time, they would be sorted alphabetically. Consider that an added bonus…
Lastly, I add the
, false parameter to
dv.taskList() to remove the file grouping.
With my slightly extended test files, I now get this output:
- [ ] 9:00 wake up [[2023-01-25]] (1st)
- [ ] 10:00 Read [[2023-01-25]] (1st)
- [ ] 1:30 Night snack [[2023-01-25]] (1st)
In Note 2
- [ ] 2:00 more night food [[2023-01-25]] (2nd)
- [ ] 9:30 brush teeth [[2023-01-25]] (2nd)
- [ ] 11:00 start work[[2023-01-25]] (2nd)
Which we can see sorts properly according to the timestamp, and doesn’t group anything based on the original files (as indicated by the mix of
2nd at the end).