# Dataview with Grouping as Header

**URL:** <https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554>\
**Category:** Help\
**Tags:** dataview\
**Created:** [January 23, 2024, 6:27pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554 "2024-01-23T18:27:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmoritz](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/b/b487fb/32.png) [@bmoritz](https://forum.obsidian.md/u/bmoritz)\
**Post date:** [January 23, 2024, 6:27pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554/1 "2024-01-23T18:27:28Z")

</div>

hey there,  
I created this dataview with java script.

 ![image](https://forum.obsidian.md/uploads/default/original/3X/f/b/fb5e71ffeb5e43ad40ba2810f5d655f15e5b0263.png)

As you can see there is a heading or grouping “A” which groups all the pages regarding a certain information provided in the yaml header. In this case Importance = A. Below Importance B and so on is listed.

However, i wondered if those groupings are also possible with dataview without js? I have checked the ressources of dataview: [Structure of a Query - Dataview](https://blacksmithgu.github.io/obsidian-dataview/queries/structure/)

but grouping does work differently here.

I want to solve this, as I want to create dataview in which i want to see files which are linked to another. e.g. from [[Homework]] and [[University]]. And I want to group for subjects.  
I am not able to use dataviewjs since i do not know how to query linked pages in dataviewjs.

Can somebody help? 😉

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Anwen](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/a/b5e925/32.png) [@Anwen](https://forum.obsidian.md/u/Anwen)\
**Post date:** [January 23, 2024, 6:33pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554/2 "2024-01-23T18:33:01Z")

</div>

Can you share the dataviewjs code you use for this ? it will be simpler to convert it to dataview.  
There is actually a Group by command in dataview.

---

<div class="post-metadata">

**Author:** ![bmoritz](https://forum.obsidian.md/letter_avatar_proxy/v4/letter/b/b487fb/32.png) [@bmoritz](https://forum.obsidian.md/u/bmoritz)\
**Post date:** [January 23, 2024, 10:47pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554/3 "2024-01-23T22:47:59Z")

</div>

here we go 🙂

```plaintext
let days = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];

let pages = dv.pages("")
		.where(p => !p.done && p["due_date"] && (p["due_date"] >= dv.date("today") || p.due > dv.date("today")));
		
for (let group of pages.groupBy(p => p["importance"])) {
	dv.header(5, group.key);
	dv.table(
	["File", "day", "due_date"], 
		group.rows
		.sort(p => p["due_date"], "asc")
		.map(p => [
			p.file.link, 
			days[dv.date(p["due_date"]).weekday - 1],
			p["due_date"].toFormat('dd.MM.yy')
			])
);
}

```

---

<div class="post-metadata">

**Author:** ![holroy](https://forum.obsidian.md/user_avatar/forum.obsidian.md/holroy/32/77699_2.png) [@holroy](https://forum.obsidian.md/u/holroy)\
**Post date:** [January 23, 2024, 11:26pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554/4 "2024-01-23T23:26:08Z")

</div>

I don’t think that’s currently possible using a pure DQL query, but I’ve written some boilerplate code which can be used in this case.

> [@Dataview TABLE, GROUP BY with headers](https://forum.obsidian.md/t/dataview-table-group-by-with-headers/51758/2):
>
> I’m sorry to say that most likely you’re not able to do that within a pure dataview query. And the image you’re showing, I’m quite certain is actually showing the result of multiple queries. One for each month. The easiest way I see for doing something similar, would be to use dataviewjs, collate all the entries, and then loop through and populate all the various types it runs across, and then present one table for each of the types. This shouldn’t be too hard to do, but it does require a littl…

In that answer I’ve tried to explain how you can build a query, apply some javascript around it (which doesn’t need loads of changes) to produce headings when a column changes value.

---

<div class="post-metadata">

**Author:** ![system](https://forum.obsidian.md/uploads/default/original/3X/b/e/bec35fbd23ab28909bb6bfe62cb32eb82dd34019.png) [@system](https://forum.obsidian.md/u/system)\
**Post date:** [April 22, 2024, 11:26pm UTC](https://forum.obsidian.md/t/dataview-with-grouping-as-header/75554/5 "2024-04-22T23:26:50Z")

</div>

Closed on April 22, 2024, 11:26pm UTC

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