Add a sort function to DataviewJs so I can see my Tasks alphabetically

What I’m trying to do

I have a folder with tasks in different notes. I have added a DataviewJs script in the front matter to list all the tasks. I want to list the tasks alphabetically.

dataviewjs
dv.taskList(dv.pages('"Home"').file.tasks
.where(t => !t.completed)
.where(t => t.text.includes("✅")))

Things I have tried

I have searched through the documentation and I found this line of code [.sort(t => t.filename ‘asc’)]

However that did not work, can anyone help?

I think you’re looking for something of the following:

  .sort(t => t.text "asc")

This will work in the dataviewjs context and when listing tasks. You can also use , "desc" if you want the text is descending order.

Hi,

I added the code and got an error:

Evaluation Error: SyntaxError: missing ) after argument list
    at DataviewInlineApi.eval (plugin:dataview:18619:21)
    at evalInContext (plugin:dataview:18620:7)
    at asyncEvalInContext (plugin:dataview:18630:32)
    at DataviewJSRenderer.render (plugin:dataview:18651:19)
    at DataviewJSRenderer.onload (plugin:dataview:18241:14)
    at e.load (app://obsidian.md/app.js:1:715749)
    at DataviewApi.executeJs (plugin:dataview:19179:18)
    at DataviewPlugin.dataviewjs (plugin:dataview:19958:18)
    at eval (plugin:dataview:19865:124)
    at t.initDOM (app://obsidian.md/app.js:1:1420748)
    at t.toDOM (app://obsidian.md/app.js:1:1417026)
    at t.sync (app://obsidian.md/app.js:1:388438)
    at e.sync (app://obsidian.md/app.js:1:364089)
    at app://obsidian.md/app.js:1:405553
    at e.ignore (app://obsidian.md/app.js:1:478915)
    at t.updateInner (app://obsidian.md/app.js:1:405349)
    at t.update (app://obsidian.md/app.js:1:405110)
    at e.update (app://obsidian.md/app.js:1:487274)
    at e._dispatch (app://obsidian.md/app.js:1:484011)
    at e.dispatch (app://obsidian.md/app.js:1:485789)
    at app://obsidian.md/app.js:1:1435823

You need a comma before the "asc".

t.text, "asc"

1 Like

Hi

I tried, this also did not work. Look at the screenshots below to see if i might be doing something else wrong.

You closed your brackets before putting the sort in.

Take one brackets off here and add it after sort.

I got a new error after i removed the 3rd bracket.

You need to match each opening bracket, with a closing bracket. So when you removed that third bracket the first dv.taskList lost its closing bracket, so add a closing bracket at the end of the .sort() statement.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.