Pulling tagged list items from particular file and showing their direct section heading?

Hi, I dont even know if this is possible with Dataview, but I’ve been searching and trying different things and cant get it to work.

I have a file called ‘journal’ where I make notes as list items under a 3rd level heading where I write the date. These list items are each tagged to show which project the list item is related to.

I would like to be able to pull a list of all the items in my journal file with a certain tag (lets say ‘PER’) , that ALSO shows the 3rd level heading directly above it - which in my set up would where I have written the date. The output would then need to look something like this:

2022-10-26

  • #PER note from the list item
  • #PER note from the list item
  • #PER note from the list item

2022-10-25

  • #PER note from the list item
  • #PER note from the list item
  • #PER note from the list item

Currently I can only get the list items to display - with no section heading (date) above.

Any help is greatly appreciated!

The level of the header is irrelevant. file.lists (as file.tasks) have a lot of metadata associated, as the section.

In DQL you can try something like this:

TABLE WITHOUT ID
	link(key, meta(key).subpath) AS Day,
	rows.Lists.text AS Content
FROM "folder-path"
WHERE file.lists
FLATTEN file.lists AS Lists
WHERE contains(Lists.tags, "#PER")
GROUP BY Lists.section

if you don’t want the header as a link use only meta(key).subpath AS Day

In DvJS:

const pages = dv.pages('"folder/subfolder/path"')
dv.taskList(pages.file.lists.where(l => l.tags.includes("#PER")).groupBy(l => l.section.subpath))

for header as a link:

const pages = dv.pages('"folder/subfolder/path"')
const groups = pages.file.lists.where(l => l.tags.includes("#PER")).groupBy(l => l.section)

for (let group of groups){
dv.header(3, dv.sectionLink(group.key.path, group.key.subpath, false, group.key.subpath));
dv.taskList(group.rows, false)
}

THANK YOU!!! This works perfectly, especially the DvJS version - exactly how I wished! I would like it to sort in the opposite order, but that’s just a small thing that I can learn to live with.

I don’t know which dvjs version you mention. But to sort by the group (the section/header) I think you can apply this (js isn’t my territory, but I think it works):

  • version 1
const pages = dv.pages('"folder/subfolder/path"')
dv.taskList(pages.file.lists.where(l => l.tags.includes("#PER")).groupBy(l => l.section.subpath).sort(k => k, 'desc'))
  • version 2
const pages = dv.pages('"folder/subfolder/path"')
const groups = pages.file.lists.where(l => l.tags.includes("#PER")).groupBy(l => l.section).sort(k => k, 'desc')

for (let group of groups){
dv.header(3, dv.sectionLink(group.key.path, group.key.subpath, false, group.key.subpath));
dv.taskList(group.rows, false)
}

It was version 2 that you so kindly provided and your update including

.sort(k => k, ‘desc’)

worked perfectly.

Thank you again!

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