How to achieve a hierarchical Dataview list without bullets but maintaining indentation

I finally figured out how to make a “Directory List” from a dataview list query.

My vault is organized with folders for each course (“Course Name”) and then within those folders are “Week/Module 1”, “Week/Module2”, etc.

-| CS-381
----| Week 1
--------| Note 1
--------| Note 2
----| Week 2

So what I’ve achieved is a directory view like this in the folder note of each course (where - is just space):

Week 1
----- Note 1
----- Note 2
Week 2
----- Note 1
----- Note 2

What results is a formatted, non-bulleted list of notes within the subfolders of each class.

The first thing you need to do is create a file named dataview-list.css with the following lines and save it inside the .obsidian/snippets folder (don’t forget to check the box in the settings to enable the snippet):

/* remove bullet for the "main points (file name) and shift
   the list to the left a bit (since there's no more bullet */
ul.dataview.list-view-ul {
	list-style: none;
}

Next, within the folder note (or any file inside a base folder) insert this dataview query:

LIST "<br><span style='padding-left: 50px'>" + join(rows.file.link, "</span><br><span style='padding-left: 50px'>") + "<br>"
WHERE contains(file.folder, this.file.folder) & type != "FolderNoteClass"
SORT file.ctime ASC
GROUP BY regexreplace(file.folder, ".*\/([^\/]+)$", "**$1**") AS Folder

We are basically adding inline styling and <span> tags to each of the rows.file.link and inserting <br> tags after each one. For some reason without those, each note link appears on the same line and is comma separated. We also bold face the Folders.

I am sure there is a more elegant way to do this but after a day fiddling with it and finding nothing out there to help with my exact use-case, I thought I would share. Hope this helps someone!

2 Likes

This is a great solution! You’ve done an excellent job of creating a custom directory list using Dataview and CSS. Let me summarize the key steps:

  • Create a dataview-list.css file in the .obsidian/snippets folder with the following CSS:
/* Remove bullet points from DataView lists */
ul.dataview.list-view-ul {
  list-style: none;
}

This removes the default bullet points from the Dataview list.

  • In your course folder note, use the following Dataview query:
LIST "<br><span style='padding-left: 50px'>" + join(rows.file.link, "</span><br><span style='padding-left: 50px'>") + "<br>"
WHERE contains(file.folder, this.file.folder) & type != "FolderNoteClass"
SORT file.ctime ASC
GROUP BY regexreplace(file.folder, ".*\\/([^\\/]+)$", "**$1**") AS Folder

Here’s a breakdown of what’s happening:

  1. The LIST command generates the formatted output.
  2. The “
    ” + join(rows.file.link, “
    ”) + “
    ” part:
  • Adds a
    (line break) before each group.
  • Wraps each file link in a tag with a left padding of 50px, to indent the notes.
  • Joins all the file links with a
    separator, creating a vertical list.
  • Adds a final
    after the list.
  1. The WHERE clause filters the list to only include files within the current course folder, and excludes “FolderNoteClass” files.
  2. The SORT clause sorts the files by creation time (oldest first).
  3. The GROUP BY clause uses a regular expression to extract the folder name and bold it using Markdown syntax (folder).

The result is a nicely formatted, indented directory list of the notes within each subfolder of the course, with the folder names bolded.

This is a great solution for organizing and navigating course materials in an Obsidian vault. Well done on figuring this out!