Sorting notes on dataviewjs

What I’m trying to do

So I have a table listing all of my uncreated notes. So far it works but i want to sort it by alphabet.

Things I have tried

const count = 1;
let d = {};
function process(k, v) {
  Object.keys(v).forEach(function (x) {
    x = dv.fileLink(x);
    if (d[x]==undefined) { d[x] = []; }

    .forEach(([k,v]) => process(k, v));
dv.table(["Non existing notes", "Linked from"],
         .filter(([k, v]) => v.length >= count)
         .sort((a, b) => b[1].length - a[1].length)
         .map(([k,v])=> [k, v.join(" • ")]))

I tried inserting the command “SORT out ASC” but it doesnt seem to work. i don’t know much about coding or Java, I just copied the above coding from a blog.

A lot of stuff is happening in that code, so I’m just going to focus on the sorting aspect. It’s correct to use a .sort( (a, b) => ... ) concept, but the code as it stands focuses on the a[1].length vs b[1].length, and sort according to these. So what are those?

They are related to arbitrary values in your list, which is a list of Object.entries(). That function in turns returns a key and an originating link list. Since array indexing starts on 0, the a[1] therefore refers to the link list, and the sorting is related to how many times the unresolved list has that particular value. This is an indication on what is the most wanted file in your vault, as the top entries are those most often linking to an unresolved file.

However, you wanted to sort on the name of the unresolved link, so then you need to focus on the first index in the list, a[0] and b[0]. Since these are strings, one of the most common way to compare these in javascript is to use localeCompare(), so then the entire line should read as:

  .sort( (a, b) => a[0].localeCompare( b[0] ) )

And that should sort the entire list on the name of the unresolved link.

Ok, so I have never used Java, I copied the whole thing from another poster. So where would I insert the line of code you just showed me? Or better yet, could you please copy the whole thing with the new code in the right place?
Thanks for all you help! This is quite the steep learning curve but its worth it.

Just replace the other .sort() line, with my version of that line. Everything else works for this purpose.

It worked, Thank you !!

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