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.

.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.


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://
    at DataviewApi.executeJs (plugin:dataview:19179:18)
    at DataviewPlugin.dataviewjs (plugin:dataview:19958:18)
    at eval (plugin:dataview:19865:124)
    at t.initDOM (app://
    at t.toDOM (app://
    at t.sync (app://
    at e.sync (app://
    at app://
    at e.ignore (app://
    at t.updateInner (app://
    at t.update (app://
    at e.update (app://
    at e._dispatch (app://
    at e.dispatch (app://
    at app://

You need a comma before the "asc".

t.text, "asc"

1 Like


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.