How can I sort notes by Folgezettel ID in Dataview using natural order?

What I’m trying to do

I’m trying to add the folgezettel numbering system into my Zettelkasten. I created a property called id because I don’t want it in the file name. But I’m experiencing an issue with the way the files get sorted.

I understand it’s something that goes beyond Obsidian, more related to the way the file system sorts the files, but maybe I’m wrong.

As you can see in the picture above, the notes 1.10 and 1.11 get placed under 1.1 instead of under 1.9a. Is there any way I can make the notes get automatically sorted the way I do without having to create the index by myself and arrange them manually?

Things I have tried

First attempt:

This is the code in the Dataview block:

```dataview
TABLE WITHOUT ID id AS "ID", link(file.link,title) AS "Nota"
WHERE id
SORT id ASC
```

Second attempt:

Another option I have implemented is:

```dataview
TABLE WITHOUT ID id AS "ID", link(file.link,title) AS "Nota"
WHERE id
SORT number(split(id, "\.")[0]) ASC, number(split(id, "\.")[1]) ASC, number(split(id, "\.")[2]) ASC
```

And although it’s better in a way, it still doesn’t work as expected.

As you can see, 1.6a is located before 1.6 and 1.6a1 under 1.6.

Third attempt:

Now I tried dataviewjs, to use a Intl.Collator, but it doesn’t work either:

```dataviewjs
dv.table(["ID", "Nota"], dv.pages()
	.where(f => f.id)
    .sort((a,b) => new Intl.Collator(undefined, { numeric: 'true'}).compare(a.id,b.id))
    .map(f => [f["id"], f.file.link]))
```

Any help will be appreciated.

Would this help?

dv.table(["ID", "Nota"], dv.pages()
	.where(f => f.id)
    .sort((a,b) => a.localeCompare(b, undefined, {numeric: true}))
    .map(f => [f["id"], f.file.link]))

This is what I get :frowning:

Evaluation Error: TypeError: a.localeCompare is not a function
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:3:22)
    at eval (plugin:dataview:8330:24)
    at Array.sort (<anonymous>)
    at Proxy.sort (plugin:dataview:8329:14)
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:3:6)
    at DataviewInlineApi.eval (plugin:dataview:18869:16)
    at evalInContext (plugin:dataview:18870:7)
    at asyncEvalInContext (plugin:dataview:18880:32)
    at DataviewJSRenderer.render (plugin:dataview:18906:19)
    at maybeRefresh (plugin:dataview:18460:18)

Sorry a, b should be a.id / b.id respectively.

dv.table(["ID", "Nota"], dv.pages()
	.where(f => f.id)
    .sort((a,b) => a.id.localeCompare(b.id, undefined, {numeric: true}))
    .map(f => [f["id"], f.file.link]))

This is what I get:

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