I try to make a Dataview table to present Filenames and Tags grouped by the Type-field.
Things I have tried
I tried the following Dataview query:
TABLE rows.file.link AS File, rows.file.tags AS Tags
FROM “101 Discretion concept”
WHERE file.name != “101 Discretion concept”
GROUP BY type
SORT file.mtime DESC
This presents all the data I want, but because some Files have more than one Tag, the third column (Tags) is not properly aligned with the Filenames column.
What can I do to correct this?
When you use GROUP BY you collate all information in lists, and loose the connection between the file and the corresponding tags, so there is not really anything to do. You’re most likely better of using just SORT, and not GROUP BY.
So try something like:
```dataview
TABLE type, file.link AS File, file.etags AS Tags
FROM "101 Discretion concept"
WHERE file.name != "101 Discretion concept"
SORT type, file.mtime DESC
```
I made one correction to your suggestion to ensure the file name was not shown twice:
TABLE WITOUT ID type, file.link AS File, file.etags AS Tags
FROM "101 Discretion concept"
WHERE file.name != "101 Discretion concept"
SORT type, file.mtime DESC
As of current version of dataview you can’t do rowspans (or colspans) within a table. This limits your option in cases like yours:
Using GROUP BY and two columns - This causes all the other lists to be collated into rows, and you can’t magically re-align two different sums of lists. Aka you can’t align one column which is the list of 5 file names, with the column a list of 2 and 3 and who-knows how many tags in the other files
Using SORT - This preserves the one file per row, and as such allows the correlation of showing the tags next to the corresponding file. Sadly, this means you’ve got the type repeating in the first column, as we don’t have the rowspan option yet
Using GROUP BY with only one column - Both the previous options has been shown queries for, but not this one. The idea here is that if you use GROUP BY, you can have one extra column, where you specifically build one list where each list element has both the file link and the tags. It’ll look different, but at least the file tags are only associated with the correct file.
Let see if we can’t build that last query option as well:
```dataview
TABLE fileAndTagList as "**File** and _tags_"
FROM "101 Discretion concept"
WHERE file.name != "101 Discretion concept"
SORT type, file.mtime DESC
GROUP BY type
FLATTEN list(map(rows, (r) =>
r.file.link + ": " + join(r.file.etags, " "))) as fileAndTagList
```
Query is untested, and joins the file tags together with space between. If you want a comma separated list, change to .... file.etags, ", "))) near the end of the query. Is this a more promising look for you?