Modifying DataviewJS code from a list to a table

What I’m trying to do

I am trying to modify the following code so that it does two things:

  1. It displays as a table.
  2. The headers are the Note name (displayed as a link) and the Type of Note (taken from a user defined metadata property.
let docs = dv.pages('-"Excluded/Folder"');
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,5)};

dv.list(randos(docs).map(e => e.file.link));

Things I have tried

I have been on the forums, google, and the documentation pages. But since I have zero coding experience, it has not been a successful process.

I got to this point, but don’t know how to get the information into the table.

let docs = dv.pages('-"Excluded/Folder"');
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,5);}

	dv.header (1, "Resurfaced Notes")
	dv.table(["Name", "Type"])	

I don’t know where you plan to get your type from, but here is a version which outputs the file link and the file.name in a table based upon your code:

```dataviewjs
let docs = dv.pages('-"Excluded/Folder"');
var randos = (docs) => {return docs.sort(() => .5 - Math.random()).slice(0,5);}

dv.table(["Link", "Name", "Size"], randos(docs)
  .map(d => [d.file.link, d.file.name, f.file.size] ))	
```

Hopefully you get the idea, and are able to accommodate to it to your needs! :-D
1 Like

This is what I was looking for. Thank you!

To answer your question about ‘type’ it is a frontmatter variable I defined for the type of note. I’m using type to create MOCs and organize my dashboard.

How would I include the variable from the note’s front matter?

If your field is called type you simply do d.type in the query above. If the name is something with a space in it, like my type you will need to d["my type"]

Thank you so much.

I now have bit of code I can just use everywhere! :saluting_face:

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