Split dataview list into columns?

I couldn’t find anything on this topic, so either it isn’t possible or it is simply obvious and I’m missing something basic :slight_smile:

What I’m trying to do

I have a list of notes that I create via dataview. As the list has grown longer and is just the notes’ title as links, I’d like to have the list displayed in multiple columns versus one very long list.

Is there a way to have have dataview or more likely a third-party column plugin, automatically split a dataview result into multiple columns (say by specifying the number of columns and have it balance the results across those columns)?

Things I have tried

All the dataview + multi-column / columns searches I’ve done refer to adding multiple-columns with the dataview results in one column and something else in another column. I just want to split a single query across multiple columns. Is this possible?

Thanks!

1 Like

If you use dataviewjs, and a query which uses the markdown variant to execute the query it should be possible to split into a given number of columns using a little array manipulation and one of the multi colum options.

The above variant would be the most precise solution, but come to think of it using the recently added slice() function and grouping it should be possible to produce a table with the wanted result as well.

I can’t code it just now, but I’ll see if I can’t produce a test query tomorrow…

So here is a sample query as a proof of concept:

```dataview
TABLE WITHOUT ID
  slice(rows.file.link, 0 * aThird, 1 * aThird) as "First third #_hide_header",
  slice(rows.file.link, 1 * aThird, 2 * aThird) as "Second third",
  slice(rows.file.link, 2 * aThird) as "Last third"
LIMIT 11
GROUP BY true
FLATTEN ceil(length(rows)/3) as aThird
```

Which also as a CSS snippet attached:

.is-live-preview .cm-tag-_,
a[href^="#_"] {
    display: none;
}

table:has([href="#_hide_header"]) {
  & thead {
    display: none;
  }
}

The query itself is actually just the LIMIT 11 which picks the first 11 files from your vault. The rest is just presentation of the result.

It produces output like this in my test vault:

The trick is to build your query, as you would like it, and then use GROUP BY true to gather all the links into one long list, and then use slice() to split it up into a given set of parts.

If you do want to see the table header line, just don’t add the css and remove the #_hide_header from the column header. Hopefully the query should be intuitive as for how to expand into more columns if one would want to do that.

3 Likes

I’m not sure what I’m doing wrong, but I get “Unrecognized function name ‘slice’” when I try to utilize your solution.

My initial query is:

list from [[]]
where contains(file.folder, "_meta") != true
sort file.name

Which just gives a list of notes with a link to this note that aren’t in my “_meta” folder.

So, using your example, I tried this:

TABLE WITHOUT ID
  slice(rows.file.link, 0 * aThird, 1 * aThird) as "First third #_hide_header",
  slice(rows.file.link, 1 * aThird, 2 * aThird) as "Second third",
  slice(rows.file.link, 2 * aThird) as "Last third"
FROM [[]]
WHERE contains(file.folder, "_meta") != true
LIMIT 11
GROUP BY true 
FLATTEN ceil(length(rows)/3) as aThird 

But as I said, that just gives the Unrecognized function name error. Am I missing a plugin or something?

Thanks so much for you help!

You might need to update dataview , as it seems you’re running on an older version. Which version of Dataview are you on?

Yes, that was it. I was on 0.5.64 and the current version is 0.5.66.

This works perfectly now. I’ve marked your above response as the solution.

Thanks!