Sorting with Dataviewjs & Metadata Menu

I’ve been messing with Dataviewjs and Metadata Menu to make my #active notes list more useful. (Essentially allowing changes from the dv table).

How do I add sort? Specifically by last priority, then last modified.

Here is my query:

```dataviewjs
const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api;

dv.table (["File", "Short Name", "Status", "Category", "Priority"],

	await Promise.all(dv.pages('#active').map(async p => [
		p.file.link, 
		await f(dv, p, "short_name"),
		p.status,
		await f(dv, p, "status_category"),
		await f(dv, p, "priority"),
		])		
))
```

Thanks!

1 Like

Oh, that seems a cool thing :slight_smile:
I didn’t explore the Metadata Menu because the first time I tried it seems some “buggy” with a list of values in fields (mainly with inline fields).

About your question, I guess you can try something like:

const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api;

dv.table (["File", "Short Name", "Status", "Category", "Priority"],

	await Promise.all(dv.pages('#active').sort(p => p.priority, 'desc').map(async p => [
		p.file.link, 
		await f(dv, p, "short_name"),
		p.status,
		await f(dv, p, "status_category"),
		await f(dv, p, "priority"),
		])		
))
1 Like

Thanks! That works great. Metadata Menu seems pretty powerful. Just the ability to change data from the dv table is huge. Examples: changing priority on my #active list, changing ratings on my books list, etc. And I haven’t even messed with the FileClass feature. That looks super cool.

Is it possible to sort on multiple things? Ideally, secondarily the rows would be sorted by last modified.

About the Metadata plugin, I need to explore it. But I noticed one thing: if in any dataview output we have the file link, then we can use the right-click in the link and choose “Manage fields” command to update any existent field in that file…

About your question, I’m not versed in js side, but, considering the @holroy tips in other post, I guess you can use two sort functions, starting from the less important. Something like:

const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api;

dv.table (["File", "Short Name", "Status", "Category", "Priority"],

	await Promise.all(dv.pages('#active').sort(p => p.file.mtime, 'desc').sort(p => p.priority, 'desc').map(async p => [
		p.file.link, 
		await f(dv, p, "short_name"),
		p.status,
		await f(dv, p, "status_category"),
		await f(dv, p, "priority"),
		])		
))

1 Like

Thank you! Exactly what I was looking for, plus now that I see the syntax I think I can figure out changing/adding later.

I didn’t know about the right click option, that’s pretty nifty. However, just to show you an example of metadata, here’s a screenshot:

image

Right from the DV table I can edit the priority (or any field).

Thanks again!

1 Like

:hushed:
So, you’re exploring the “interface” to change that values! great!

Exactly!

You don’t happen to know where I would add omits, do you?

Sorry to keep pestering. I was just wrapping my head around regular DV when I found Metadata Menu, and it’s just too powerful. DVJS is definitely a full step ahead of me.

Thanks

Existing codeblock:

const {fieldModifier: f} = this.app.plugins.plugins["metadata-menu"].api;

dv.table (["File", "Short Name", "Status", "Category", "Priority"],

	await Promise.all(dv.pages('#active').sort(p => p.file.mtime, 'desc').sort(p => p.priority, 'desc').map(async p => [
		p.file.link, 
		await f(dv, p, "short_name"),
		await f(dv, p, "status"),
		await f(dv, p, "status_category"),
		await f(dv, p, "priority"),
		])		
))