In DataviewJS() how can I filter by page content in dv.pages()?

If I have a dv.pages() function like this, how can I modify it so it also filters to only pages that contain [ ] (incomplete tasks). I did some looking up but couldn’t find answers.

dv.pages("(1) Misc Notes/tasks").where(p.Completed != true && p.Status != 'Waiting' && p["Task Size"] != 'Large')

Someone showed me a code sample here to solve it, which I adapted:

let pages = dv.pages();
let rows = [];

for (let [index, p] of Object.entries(pages.values)) {
	var has_tasks = false;
	var content = await dv.io.load(p.file.path); 
	if (content.contains("behind")){
		rows.push([p.file.link]);
	}
}

dv.table(["File"],
  rows.map(v => v) );

As stated in the documentation, where takes a function that returns a boolean value.

export interface DataArray<T> {
    /** Filter the data array down to just elements which match the given predicate. */
    where(predicate: (elem: T, index: number, arr: T[]) => boolean): DataArray<T>;
}

So this should work:
dv.pages("(1) Misc Notes/tasks").where(p => p.Completed != true && p.Status != 'Waiting' && p["Task Size"] != 'Large')

1 Like

But I want to see pages with a Completed: true property, but contains incomplete tasks in the note body.

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