What I’m trying to do
Don’t Include Subtasks in Table of Tasks
Things I have tried
Attempt with Dataview:
TABLE WITHOUT ID
file.link AS "File",
regexreplace(Tasks.text, "\[.*$", "") AS Task,
default(object(
" ", "backlog",
"/", "in progress",
"-", "cancelled",
"x", "completed")[Tasks.status], "?") AS Status,
Tasks.priority AS "Priority",
Tasks.duration AS "Duration",
Tasks.scheduled - date(today) AS "Days until Scheduled",
Tasks.due - date(today) AS "Days until Due"
FROM "Admin"
FLATTEN file.tasks AS Tasks
WHERE file.tasks AND !children
LIMIT 20
Attempt with DataviewJS:
const priorityOrder = {
"highest": 1,
"high": 2,
"medium": 3,
"low": 4,
"lowest": 5,
"null": 6 // Handle null or undefined priorities
};
// Retrieve pages from the Admin folder
const pages = dv.pages('"Admin"');
// Process the pages
const tasks = pages
.flatMap(page => page.file.tasks || []) // Safeguard against missing file or tasks
.filter(task => task.text) // Filter tasks
.sort((a, b) => (priorityOrder[a.priority] || priorityOrder["null"]) - (priorityOrder[b.priority] || priorityOrder["null"])); // Custom sorting based on priority
// Generate the table
dv.table(
["File", "Tasks", "Status", "Priority", "Duration", "Days until Scheduled", "Days until Due"],
tasks
.slice(0, 20) // Limit to 10 results
.map(task => {
const status = {
" ": "backlog",
"/": "in progress",
"-": "cancelled",
"x": "completed"
}[task.status] || "?";
const filePath = task.path ? dv.fileLink(task.path) : "No Link"; // Safeguard against missing file path
return [
filePath,
task.text,
status,
task.priority,
task.duration,
task.scheduled ? dv.date(task.scheduled) - dv.date("today") : null,
task.due ? dv.date(task.due) - dv.date("today") : null
];
})
);
Question
In either version (dataview or dataviewjs), how do I filter out the subtasks? (I assume within a WHERE statement for dataview and within a .filter function for dataviewjs). Is there anything at all that differentiates subtasks from tasks that can be used?