How can I collect all list item contains certain tag in one page and keep nested structure(no flatten)

What I’m trying to do

I have several daily notes, let’s name them by date. (e.g. 2023-03-01.md, 2023-03-02.md)

2023-03-01.md

  • #workout
    • bench press
      • 10 x 8
      • 10 x 7
    • dumbbell press
      • 20 x 8
      • 20 x 7
  • other unrelated list item 1
  • other unrelated list item 2

2023-03-02.md

  • #workout
    • squat
      • 110 x 8
      • 120 x 7
    • hacksquat
      • 120 x 8
      • 120 x 7
  • other unrelated list item 1
  • other unrelated list item 2

I want to have a dashboard that collects all the workout items on a single page. Like a table with two columns, one is the filename containing the #workout item, the other is the #workout item content. (I want it keeps its original nested structure, don’t flatten). Just like:

2023-03-01.md

  • #workout
    • bench press
      • 10 x 8
      • 10 x 7
    • dumbbell press
      • 20 x 8
      • 20 x 7

2023-03-02.md

  • #workout
    • squat
      • 110 x 8
      • 120 x 7
    • hacksquat
      • 120 x 8
      • 120 x 7

Things I have tried

I have read the document. I know there is an implicit field called file.lists which collects all the lists in a file. but I don’t know how to display it in an original nested way.

file.lists.text will display the flattened result which is not the result expected.

I also tried not get what I expected.

list without id
L.text
from #workout 
flatten file.lists as L
where contains(L.tags, "#workout")

I search several keywords (group by tag, keep nested item) but only got flattened examples. Please point me out a way to solve this. Thanks in advance.

If DQL were to support the “taskList” Query Type, use it directly.
Otherwise, use the DVJS10.

Topic

Summary
  • How to get list items and render the result with the desired structure?

Test

Summary
  • dataview: v0.5.55

Input

Summary

dictionary files

  • Location: “100_Project/01_dataviewjs/01_by_example/Q33_workout/Q33_test_data”

folder: List_items

  • filename : dic_19550301
```md
---
Date: 1955-03-01
---
#workout


- #workout
  - bench press
    - 10 x 8
    - 10 x 7
  - dumbbell press
    - 20 x 8
    - 20 x 7

- #Test/d01
  - bench press
    - 1 x 8
    - 1 x 7
  - dumbbell press
    - 1 x 8
    - 1 x 7
```

  • filename : dic_19550401
```md
---
Date: 1955-04-01
---
#workout

- #workout
  - squat
    - 110 x 8
    - 120 x 7
  - hacksquat
    - 120 x 8
    - 120 x 7

- #Test/d01
  - squat
    - 1 x 8
    - 1 x 7
  - hacksquat
    - 1 x 8
    - 1 x 7

```

folder: Task_items

  • filename : dic_19550901
```md
---
Date: 1955-09-01
---
#workout


- [ ] #workout
  - bench press
    - 10 x 8
    - 10 x 7
  - dumbbell press
    - 20 x 8
    - 20 x 7

- [x] #Test/d01
  - bench press
    - 1 x 8
    - 1 x 7
  - dumbbell press
    - 1 x 8
    - 1 x 7
```

  • filename : dic_19551001
```md
---
Date: 1955-10-01
---
#workout

- [ ] #workout
  - squat
    - 110 x 8
    - 120 x 7
  - hacksquat
    - 120 x 8
    - 120 x 7

- [x] #Test/d01
  - squat
    - 1 x 8
    - 1 x 7
  - hacksquat
    - 1 x 8
    - 1 x 7

```

DVJS10_filter_fLists_get_list_items_and_taskList

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS10
_filter_fLists
_get_list_items
_and_taskList
file.lists no 1.To gather the file.lists
1.1 To get list items
1.2 To filter by L.tags

2.To display the result as list items [with the desired structure]

Notes:

Summary

Q1: How to modify the DVJS10 if the SourcePath is ‘#workout’?

Summary_Q1
Original Example: Q1 (To be modified)
```dataviewjs
dv.taskList(
    dv.pages('"100_Project/01_dataviewjs/01_by_example/Q33_workout/Q33_test_data" AND #workout')
      .file.lists
      .where((L) => !L.task)
      .where((L) => dv.func.contains(L.tags, "#workout")),
    true
);
```

A1_11:

Another Example:
```dataviewjs
dv.taskList(
    dv.pages('#workout')
      .file.lists
      .where((L) => !L.task)
      .where((L) => dv.func.contains(L.tags, "#workout")),
    true
);
```

Code DVJS10_filter_fLists_get_list_items_and_taskList

Summary_code
title: DVJS10_filter_fLists_get_list_items_and_taskList => 1.To gather the file.lists 1.1 To get list items 1.2 To filter by L.tags 2.To display the result as list items [with the desired structure] 
collapse: close
icon: 
color: 
```dataviewjs
// M11. define FLST: gather all relevant List items
// For List_items: !L.task
// For Task_items: L.task
// #####################################################################
let FLST = dv
    .pages('"100_Project/01_dataviewjs/01_by_example/Q33_workout/Q33_test_data" AND #workout')
    .file.lists
    .where((L) => !L.task)
    .where((L) => dv.func.contains(L.tags, "#workout"));


// M31. output FLST:
// #####################################################################
dv.taskList(FLST, true);

```

Screenshots(DVJS10): dv.taskList(FLST, true)

Screenshots(DVJS10): dv.taskList(FLST, false)


Reference

Summary

Query Types

dv.taskList(tasks, groupByFile)


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