Dataview filter specific value for sorting

Things I have tried

I was hoping I could use the ternary form - something like:

TABLE type AS "Type", file.tags[0] AS "Status", file.mtime AS "Last updated"
 FROM [[Personal/Personal Index]]
WHERE !contains(file.tags, "#MoC")
 SORT filter(file.tags[0], (status) => status = "#status/on-hold" ? 1 : 0) ASC,
      file.mtime DESC

but that doesn’t seem to be valid.

What I’m trying to do

I want to sort a specific status to the bottom of a table, but leave everything else sorted on date. Is this possible with dataview or do I need to fall back to dataviewjs here?

(I guess ideally it would be nice to be able to leave the TABLE in a dataviewjs script and just define a function for the filtering, but that doesn’t work either - I guess it’s all js or no js and mix-and-match is out?

Hi.
I just don’t understand this part. To start, filter() only works with an array. But file.tags[0] isn’t an array (because the [0]).
This part - "#status/on-hold" ? 1 : 0 I just don’t understand what it means. I guess is a JS code, but you can’t use js in dql queries (only the functions defined… well, the use of => is similar, but with a defined syntax).
I guess you need to use the function choice().
Maybe something like:

SORT choice(file.tags[0] = "#status/on-hold", 2, 1) ASC, file.mtime DESC

It means:

  1. if file.tags[0] = "#status/on-hold"replace by the number 2
  2. if not, replace by number 1
  3. once you define the ascending sort, then they list first all the 1 and then the 2 cases.
  4. file.mtime DESC solves the rest

Ah, sorry, the [0] shouldn’t have been there, my mistake there. I’d been changing stuff around a lot :slight_smile:

Yes condition ? if true : if false is a JS ternary that’s basically shorthand for if ..then..else

But the choice is I think what I probably do want here, thanks!

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