DataviewJS to show pdfs - how to sort by asc?

What I’m trying to do

I have a dataviewjs query to list pdfs. The query works but the order is desc. I would like it to be asc. How do I accomplish this?

Things I have tried

I have searched for an answer and found some examples of code that is similar to what I want but nothing has worked. I’m a novice at coding. Any help is appreciated.

Here is the dataviewjs that works but in desc order:

```dataviewjs
const pdfFiles = app.vault.getFiles().filter(file => file.extension === 'pdf')
dv.list(pdfFiles.map(file => dv.fileLink(file.path)))
```

Hi, I just quickly edited your post to include extra 4-backticks around your 3-backticks code, so the

```dataviewjs
```

shows up too.

1 Like

I misspelled “order” in title but can’t correct it. Can you fix that also. Thank you.

1 Like

Thank you to @DiCaver for the solution below. I had to add the sort line as @DiCaver suggested. Works like charm. See also: Code to list PDFs in a folder in Numerical / Alphabetical order - #4 by DiCaver

```dataviewjs
const pdfFiles = app.vault.getFiles().filter(file => file.extension === 'pdf')
.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true, sensitivity: 'base' }));
dv.list(pdfFiles.map(file => dv.fileLink(file.path)))
```
1 Like