DATAVIEW: Subfolders in list organized by folder show up at the bottom of the whole list, rather

Topic : 1/2

Summary
  • How to create an indented line for a subfolder within the grouped folder in list view?
    • DQL10
    • mDVJS01 + Q30_DQL10a_JS.js + Q30_ParentFolder_Config_a.md: It supports three different use cases.

Test

Summary
  • dataview: v0.5.55

Input

Summary

the current notes

  • Location: “100_Project/02_dataview/Q30_CurrentFolder/Q30_test_data/C0_Parent”

  • filename : Q30_DQL01_C0
```md
### Q30_DQL01


```

  • filename : Q30_DQL10_C0
````md
### Q30_DQL10


````

  • filename : Q30_mDVJS01_C0 or Q30_index_C0
````md
### Q30_mDVJS01


````

dictionary files

  • Location: “100_Project/02_dataview/Q30_CurrentFolder/Q30_test_data/C0_Parent”

folder: C1_04

  • filename : dic_19530401
```md
---
date: 1953-04-01
---

```

  • filename : dic_19530406
```md
---
date: 1953-04-06
---

```

folder: C1_05

  • filename : dic_19530501
```md
---
date: 1953-05-01
---

```

  • filename : dic_19530506
```md
---
date: 1953-05-06
---

```

folder: C1_05/C2_01

  • filename : dic_19530511
```md
---
date: 1953-05-11
---

```

  • filename : dic_19530516
```md
---
date: 1953-05-16
---

```

folder: C1_05/C2_02

  • filename : dic_19530521
```md
---
date: 1953-05-21
---

```

  • filename : dic_19530526
```md
---
date: 1953-05-26
---

```

folder: C1_06

  • filename : dic_19530601
```md
---
date: 1953-06-01
---

```

  • filename : dic_19530606
```md
---
date: 1953-06-06
---

```

DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE: For Debugging

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL01
_create_Indentations
_for_subfolder
_within_grouped_folder
_and_LIST
file.folder:
a string

this.file.folder:
a string
yes 1.To filter by file.folder

2.To define field variables:
2.1 To define three field variables, such as SubFolderName, SubFolderWithPathRelativeToParent, ParentFolderName
2.2 To define three field variables, such as SubFolderWithPath, pName, and sName
2.3 To define ten field variables, such as C0, C1,… ,C9

3.To define field variables:
3.1 To define one field variable CN
3.2 To define one field variable SomeIndentation for Indentations

4.To sort by file.folder in ascending order
5.To group by SubFolderWithPath
6.To define two field variables, such as P_SomeIndentation and P_SubFolderName

7.To render as a table

Code DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE

Summary_code

NOTE:
The location for the DQL01 is “100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent”.

title: DQL01_create_Indentations_for_subfolder_within_grouped_folder_and_TABLE => 
collapse: close
icon: 
color: 
```dataview
TABLE WITHOUT ID
      rows.file.link,
      rows.CN,  
      rows.ParentFolderName,
      rows.SubFolderName,
      rows.SubFolderWithPath

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)


FLATTEN regexreplace(file.folder, "^.*\/([^/]+)$", "$1") AS SubFolderName
FLATTEN regexreplace(file.folder, C0_Parent + "\/", "") AS SubFolderWithPathRelativeToParent
FLATTEN regexreplace(C0_Parent, "^.*\/([^/]+)$", "$1") AS ParentFolderName


FLATTEN SubFolderWithPathRelativeToParent AS SubFolderWithPath
FLATTEN ParentFolderName AS pName
FLATTEN SubFolderName AS sName


FLATTEN choice(sName = pName, "C0", "") AS C0
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+)$", "C1"), "") AS C1
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){1,1})$", "C2"), "") AS C2
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){2,2})$", "C3"), "") AS C3
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){3,3})$", "C4"), "") AS C4
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){4,4})$", "C5"), "") AS C5
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){5,5})$", "C6"), "") AS C6
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){6,6})$", "C7"), "") AS C7
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){7,7})$", "C8"), "") AS C8
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){8,})$", "C9"), "") AS C9


FLATTEN C0 + choice(C1="C1", "C1", "") + choice(C2="C2", "C2", "") + choice(C3="C3", "C3", "") +
        choice(C4="C4", "C4", "") + choice(C5="C5", "C5", "") + choice(C6="C6", "C6", "") + 
        choice(C7="C7", "C7", "") + choice(C8="C8", "C8", "") + choice(C9="C9", "C9", "") 
        AS CN


FLATTEN "  " AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation


SORT file.folder ASC
GROUP BY SubFolderWithPath AS G_SubFolderWithPath


FLATTEN rows.SomeIndentation[0] AS P_SomeIndentation
FLATTEN rows.SubFolderName[0] AS P_SubFolderName
```

Screenshots(DQL01):


DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST

Summary

Main DQL

Code Name Data type Group By Purposes Remark
DQL10
_create_Indentations
_for_subfolder
_within_grouped_folder
_and_LIST
file.folder:
a string

this.file.folder:
a string
yes 1.To define field variables C0_Parent
2.To filter file.folder by C0_Parent

3.To define field variables:
3.1 To define three field variables, such as SubFolderName, SubFolderWithPathRelativeToParent, ParentFolderName
3.2 To define three field variables, such as SubFolderWithPath, pName, and sName
3.3 To define ten field variables, such as C0, C1,… ,C9

4.To define field variables:
4.1 To define one field variable CN
4.2 To define one field variable SomeIndentation for Indentations

5.To sort by file.folder in ascending order
6.To group by SubFolderWithPath
7.To define two field variables, such as P_SomeIndentation and P_SubFolderName
8.To render as a list with desired structure
The DQL10 is based on the DQL01 in the topic.

Notes

Summary

Q1: How to modify the following code in order to use the DQL10 in any page in any location?

Summary_Q1
Original Example: Q1 (To be modified)
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)
```

A1_11:

Another Example: A1_11

NOTE:

  1. Remove the FROM expression.
  2. The DQL10 performance is poor without the FROM expression.
  3. For best performance, use the mDVJS01 instead of the DQL10, where the FROM expression is removed.
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)


FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)
```

Q2: How to customize different folder levels of Indentations?

Summary_Q2
Original Example: Q2 (To be modified)
```dataview

FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation
```

A2_21: Add Circled Sans-Serif Digits

Another Example: A2_21
```dataview

FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": "➁" + INDT,
    "C2": INDT + "➂" + INDT,
    "C3": INDT + INDT + "➃" + INDT,
    "C4": INDT + INDT + INDT + "➄" + INDT,
    "C5": INDT + INDT + INDT + INDT + "➅" + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + "➆" + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + "➇" + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + "➈" + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + "➉" + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_21):


A2_22: Add Vertical Lines

Another Example: A2_22
```dataview

FLATTEN "|&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_22):


A2_23: Add Vertical Lines with HTML formatting

Another Example: A2_23
```dataview

FLATTEN "<span style='color:grey'>" + "|&ensp;&ensp;" + "</span>" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation

```
Screenshots(A2_23):


Code DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST

Summary_code

NOTE:

  1. It supprts up to eight levels of subfolders (C0~C8) for the file.folder.
  2. The file.folder subfolders at or above nine levels (C9, C10~) are rendered as nine levels.
  3. The location for the DQL10 is “100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent”.

C0=Parent
C1=Childern of C0_Parent
C2=Childern of C1
C3=Childern of C2
C4=Childern of C3
C5=Childern of C4
C6=Childern of C5
C7=Childern of C6
C8=Childern of C7
C9=Childern of C8, C9, C10, C11, and so on

title: DQL10_create_Indentations_for_subfolder_within_grouped_folder_and_LIST =>1.To define field variables `C0_Parent` 2.To filter `file.folder` by `C0_Parent` 3.To define field variables: 3.1 To define three field variables, such as `SubFolderName`, `SubFolderWithPathRelativeToParent`, `ParentFolderName` 3.2 To define three field variables, such as `SubFolderWithPath`, `pName`, and `sName` 3.3 To define ten field variables, such as `C0`, `C1`,... ,`C9` 4.To define field variables: 4.1 To define one field variable `CN` 4.2 To define one field variable `SomeIndentation` for Indentations 5.To sort by `file.folder` in ascending order 6.To group by `SubFolderWithPath` 7.To define two field variables, such as `P_SomeIndentation` and `P_SubFolderName` 8.To render as a list with desired structure
collapse: close
icon: 
color: 
```dataview
LIST WITHOUT ID
     P_SomeIndentation + 
     P_SubFolderName + 
     map(rows.file.link, (e) =>  "<br>" + P_SomeIndentation + "⦁ " + e)

FROM "100_Project/02_dataview/Q30_ParentFolder/Q30_test_data/C0_Parent"
FLATTEN this.file.folder AS C0_Parent
WHERE startswith(file.folder, C0_Parent)


FLATTEN regexreplace(file.folder, "^.*\/([^/]+)$", "$1") AS SubFolderName
FLATTEN regexreplace(file.folder, C0_Parent + "\/", "") AS SubFolderWithPathRelativeToParent
FLATTEN regexreplace(C0_Parent, "^.*\/([^/]+)$", "$1") AS ParentFolderName


FLATTEN SubFolderWithPathRelativeToParent AS SubFolderWithPath
FLATTEN ParentFolderName AS pName
FLATTEN SubFolderName AS sName


FLATTEN choice(sName = pName, "C0", "") AS C0
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+)$", "C1"), "") AS C1
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){1,1})$", "C2"), "") AS C2
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){2,2})$", "C3"), "") AS C3
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){3,3})$", "C4"), "") AS C4
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){4,4})$", "C5"), "") AS C5
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){5,5})$", "C6"), "") AS C6
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){6,6})$", "C7"), "") AS C7
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){7,7})$", "C8"), "") AS C8
FLATTEN choice(sName != pName, regexreplace(SubFolderWithPath, "^([^/]+(\/[^/]+){8,})$", "C9"), "") AS C9


FLATTEN C0 + choice(C1="C1", "C1", "") + choice(C2="C2", "C2", "") + choice(C3="C3", "C3", "") +
        choice(C4="C4", "C4", "") + choice(C5="C5", "C5", "") + choice(C6="C6", "C6", "") + 
        choice(C7="C7", "C7", "") + choice(C8="C8", "C8", "") + choice(C9="C9", "C9", "") 
        AS CN


FLATTEN "&ensp;&ensp;" AS INDT

FLATTEN {
    "C0": "",
    "C1": INDT,
    "C2": INDT + INDT,
    "C3": INDT + INDT + INDT,
    "C4": INDT + INDT + INDT + INDT,
    "C5": INDT + INDT + INDT + INDT + INDT,
    "C6": INDT + INDT + INDT + INDT + INDT + INDT,
    "C7": INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C8": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT,
    "C9": INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT + INDT
}[CN] AS SomeIndentation


SORT file.folder ASC
GROUP BY SubFolderWithPath AS G_SubFolderWithPath


FLATTEN rows.SomeIndentation[0] AS P_SomeIndentation
FLATTEN rows.SubFolderName[0] AS P_SubFolderName
```

Screenshots(DQL10):


Conclusion

Summary
  • Althought the FROM expression in DQL doesn’t support FROM this.file.folder, the mDVJS01 does.
  • For best performance, use the mDVJS01 instead of the DQL10, which the FROM expression is removed.

Reference

Summary

Emojis

Z Notation Spot

Vertical Line

Dingbat Circled Sans-Serif Digit

Q83_FolderNote: Regular Expressions

Q88_header: DQL30

Q78_MediumCat: mDVJS01

How to reuse user-defined functions, a DVJS code, or a DQL query?

Summary

1 Like