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!

2 Likes

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"),
		])		
))

Hello i followed example which you proposed here (and many others examples from this plugin)

but always end up with following error

Evaluation Error: TypeError: fieldContainer.setAttr is not a function
    at fieldModifier (plugin:metadata-menu:8854:18)
    at eval (plugin:metadata-menu:9087:41)
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:6:11)
    at Array.map (<anonymous>)
    at Proxy.map (plugin:dataview:11738:39)
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:4:105)
    at eval (eval at <anonymous> (plugin:dataview), <anonymous>:10:6)
    at DataviewInlineApi.eval (plugin:dataview:15671:16)
    at evalInContext (plugin:dataview:15672:7)
    at asyncEvalInContext (plugin:dataview:15679:16)

did you guys encounter something similar ?

Do you want to have that comma after the await priority line? Doesn’t that create an extra undefined element in your map values?

Another question, why do you introduce the await Promise.All() into the mix? Is that a requirement of the metadata plugin? (I’ve not looked into that plugin, so my responses so far are based on general javascript knowledge)

i copied the code from conversation above in this scenario (but yes comma is optional there)

I am a newbie to the javascript, again i copied the code above. In case i would take it away it would produce zero data.

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