DataviewJS Table - How to sort GroupBy heading

Things I have tried

for (let group of dv
	.pages('"Work/Projects" and !#type/dashboard')
	.where(p => p.status !== "completed")
	.sort(p => p.status, "asc")
	.groupBy(p => p.status)) {
		dv.header(3, group.key);
		dv.table(["Project", "Start Date", "Due Date"],
			group.rows
				.sort(p => p.defer_date, 'desc')
				.map(p => [p.file.link, p.defer_date, p.due_date]))
		}

What I’m trying to do

I am currently trying to list my incomplete projects (each on their own page) in a table, grouped by their status and sorted by their start date.

My code above essentially does that, but I would like the “on hold” section to come after the “on-going” section.

Preferably, I would like to sort the group headers (on hold, and on-going) by a predetermined order, as noted in in this solution (unfortunately this solution doesn’t use DataviewJS), but if that can’t be done, then at least if I can sort the group headers.

In my code above, I’ve tried using .sort(p => p.status, "asc") and .sort(p => p.status, "desc") and neither makes any difference.

Any help would be appreciated.

Hi.
Try this:

for (let group of dv
	.pages('"Work/Projects" and !#type/dashboard')
	.where(p => p.status !== "completed")
	.sort(p => p.status, "asc")
	.groupBy(p => p.status).sort(g => g.key, 'desc')) {
		dv.header(3, group.key);
		dv.table(["Project", "Start Date", "Due Date"],
			group.rows
				.sort(p => p.defer_date, 'desc')
				.map(p => [p.file.link, p.defer_date, p.due_date]))
		}

thanks!

so it was a matter of make it .sort(p => p.key, 'desc') instead of .sort(p => p.status, 'desc')

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