Filtering tasks from specified headers with dataviewJS

What I’m trying to do

I’m trying to create progress bars using dataview JS, using tasks that belong to a specific heading.
My problem is, I can’t figure out how to target tasks that are under a specified header.

Things I have tried

I have searched the docs and came across a way to target lists under headers in normal dataview, but have not found a way to do it in dataviewJS (which is needed for creating the progress bar)

If anyone knows how to do this, I would really appreciate your help.

console.log is your friend in combination with Developer Tool > Console. Build your script, and do a .map() where you print the task section link information. There you should see references to the subpath denoting the header, if present, of the task.

Thank you for your reply!

Using your advice and chatGPT I haphazardly got it to work.

For future readers, this is what I used:

// Change the names below to you desired folder/note and your desired heading
const tasks = dv.pages('"YourFolder/YourNote"')[0]?.file.tasks.filter(task => task.section.subpath === "YourHeading") || [];

const completedTasks = tasks.filter(task => task.completed);
const totalTasks = tasks.length;
const completedTasksCount = completedTasks.length;

const message = totalTasks === 0 ? "No tasks found." :

// Your css here

` <progress value="${Math.round((completedTasksCount / totalTasks) * 100)}" max="100" style="width: 30%;"></progress>`;


Seems legit when just skimming the code, however if you’re getting just that one page, you could use instead of getting the first element from dv.pages().

1 Like

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