Dataviewjs problem with sorting files

I hope someone can help me :slight_smile:

i have a code that gives me all the notes from the folder “book” embedded.

unfortunately i don’t understand the sorting.

the sorting should be

1 k
2 k
3 k

the problem is somehow the sorting.
if i create a file in the folder “book” with the name 2.1 k for example, everything gets mixed up …

is there perhaps a solution?

filter(p => p.file?.tags.some(tag => tag.startsWith("#kapitel"))).
forEach(p => dv.paragraph(dv.fileLink(, true)))

all notes that have the tag #kapitel are output (embedded)

What is your intended sorting? Just alphanumeric on the file name? On some field, or what?

If it’s a field, you could in some cases achieve the sorting by adding something like .sort(a => a.field) into the chain before the .forEach, but it’s hard to tell just from the information you’ve given so far.

the sorting should be alphabetical according to the names of the files…

The following is untested, but what if you sort the files before you do the filtering? Would that give you the correct order? Also, I’m slightly apprehensive whether the forEach() respects the order or not.

But try this one and see if it’s any better:

  .sort(p =>
  .filter(p => p.file?.tags.some(tag => tag.startsWith("#kapitel")))
  .forEach(p => dv.paragraph(dv.fileLink(, true)))
1 Like

That works great. thanks for the help. :grinning: :grinning: :grinning: :grinning: :grinning:

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