DataviewJS Snippet Showcase

You can have a look at my upcoming event calendar here, it should give you some pointers.

It creates a visual calendar view of all upcoming events:

this is my weekly statistic graph
image
image
image

I’m trying to build the DataviewJS query. That is extracting the vault path and building the full path for image by combining YAML Header where I have only name of the image with extension as string

YAML Header

name: Original
number: 1
image: "image12.jpg"
sphere: Earth

DataviewJS query

dataviewjs

//@ts-ignore

let adapter = app.vault.adapter;

 // VAULT PATH
const vault = adapter.getBasePath();

 // PATH WHERE I HAVE IMAGES
const vault_images = vault + "/Resources/Images/"

const pages = 
		dv.pages()
		.where(b => b.file.frontmatter.sphere === 'Earth')
		.sort(b => b.file.frontmatter.number)
		.array()
	.map(({file}) => {

 // PROBLEMATIC LINE
	return ["![](" + vault_images + file.frontmatter.image + ")",file.name, file.frontmatter.number]
})

dv.table(["Image", "Name", "Number"], pages)

Result

It gives me the table of all items, but there is just one image propery for all records. It looks like it is giving me all images as object.


I will really appreciate somebody who can help me to adjust the code :pray:t2:

Love it

1 Like

SHOW IMAGE BASED ON YAML PARAMETER

IMAGE FILE: base_color.jpg

Note

---
date:
image: color
tags: 
---
dataviewjs

const prefix = "base"      /// image prefix
const ext = ".jpg"         /// image extension
const size = "200"         /// image size

const cover = "![[" + prefix + "_" + dv.current().image + ext + "|" + size + "]]"
dv.paragraph(cover)

I am using $=dv.pages().length in a vault info bar to show the total number of files in the vault but I want to also have a inline snipped that shows the number of files modified today, what code would I use?

  • You could use the following Inline DataviewJS Query.

### inDVJS10
QTY_modified_today=`$=dv
    .pages()
    .where((page) => page.file.mday.toFormat("yyyy-MM-dd") === dv.func.date("today").toFormat("yyyy-MM-dd")).length;`

1 Like

Topic

Summary
  • How to filter the data by the filename of a link?

Test

Summary
  • dataview: v0.5.46

input

Summary

dictionary files

  • Location: “100_Project/02_dataview/Q17_Purchases/Q17_test_data”

03

  • filename : dic_19920301
---
date: 1992-03-01
purchases:
  - store: "[[some store]]"
    item: some item
    comments: comments
  - store: "[[another store]]"
    item: another item
    comments: other comments
---



04

  • filename : dic_19920401
---
date: 1992-04-01
purchases:
  - store: "[[some store]]"
    item: apples
    comments: 
  - store: "[[some store]]"
    item: oranges
    comments: 
---



05

  • filename : dic_19920501
---
date: 1992-05-01
purchases:
  - store: "[[another store]]"
    item: potatoes, potatoes
    comments: 
  - store: "[[another store]]"
    item: a very big watermelon
    comments: 
---



06_only_one_record

  • filename : dic_19920601
---
date: 1992-06-01
purchases:
  - store: "[[some store]]"
    item: some item
    comments: comments
---



07_including_an_empty_record

  • filename : dic_19920701
---
date: 1992-07-01
purchases:
  - store: "[[some store]]"
    item: some item
    comments: comments
  - store: 
    item: 
    comments: 
---



08_null

  • filename : dic_19920801
---
date: 1992-08-01
purchases:
---



09_undefined

  • filename : dic_19920901
---
date: 1992-09-01
---



10_excluding_store_not_link

  • filename : dic_19921001
---
date: 1992-10-01
purchases:
  - store: "another store"
    item: another item
    comments: comments
---



DQL10_filter_by_filename_of_a_link

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10_filter_by
_filename_of_a_link
P.store:
a link
no 1.To filter by purchases
2.To break up a list like purchases in a file into each individual P in a file and let P = each element of purchases of each page
3.To filter by P and P.store
4.To define a field variable s_filename_of_link
5.To filter by s_filename_of_link
6.To sort by date in descending order
7.To display the result as a table
The DQL10 is based on the DQL10 in the following topic.
- Solutions: by Justdoitcc

DQL10_filter_by_filename_of_a_link

Summary_code
title: DQL10_filter_by_filename_of_a_link =>1.To filter by `purchases` 2.To break up a list like `purchases` in a file into each individual `P` in a file and let P = each element of `purchases` of each page 3.To filter by `P` and `P.store` 4.To define a field variable `s_filename_of_link` 5.To filter by `s_filename_of_link` 6.To sort by `date` in descending order 7.To display the result as a table
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID 
      file.link AS "File",
	  P.store AS "store",
	  P.item AS "item",
	  P.comments AS "comments",
      s_filename_of_link AS "filename_of_store"
      
FROM "100_Project/02_dataview/Q17_Purchases/Q17_test_data"
WHERE purchases != null       

FLATTEN purchases AS P
WHERE P != null AND P.store != null
FLATTEN regexreplace(meta(P.store).path, "^(.*/)(.+)(\.md)$", "$2") AS s_filename_of_link
WHERE contains(s_filename_of_link, "another store")
SORT date DESC
```

Screenshots(DQL10)


Oh! I didn’t know this is possible!
That’s why I developed my plugin “Table to CSV Exporter”. :wink: