Dataview: sort groups by line

Hello. Getting tasks from kanban board, I need headers to be sorted by line - by place in file, if I drag kanban list to begin of file it should be first in dw, but however I tried - headers always sorting by name.

Things I have tried

Task
FROM "Projects"
WHERE !completed
GROUP BY header
LIMIT 1
SORT rows.file.header.line

Tried any combinations - same.

I don’t know what header refers to, but does this work at all? (Can change the sort order from ASC [ascending] to DESC [descending].)

```dataview
Task
FROM ""
WHERE !completed
GROUP BY header
SORT min(rows.header) ASC
```

It doesn’t :frowning:
Tried you option as is, and with section instead header, ASC and DESC - it orders by name anyway

Hope someone else can help. Sorry.

What is the header you’re trying to sort in?

And if you want to sort on some like number, which line in which file do you want to use? (What’s on that line? And how would you potentially handle different files with varying line number? )

Are you able to show some examples on typical input, and what you want add output?

This is an attempt to implement dependent tasks.

For example, this is source kanban-board:

LIMIT shows tasks only from one header (kanban-list). When task 1 and task 2 from first list will be done, dw shows second list etc. header or section here - name of list. Order should be from left-to-right (from top to bottom in markdown view):

  1. should_be_first
  2. second
  3. last

But it sorts by name:

  1. last
  2. second
  3. should_be_first

SORT by line - here I tried to sort headers by position in the file.

If everything is contained in the same file try the following:

```
Task
FROM "Projects"
WHERE !completed
SORT line
GROUP BY meta(section).subpath
LIMIT 1
```

I’m still a little unsure on how you’re actual file looks, but at least this variant should refer to existing fields available.

If this doesn’t work could you please return the result of this query:

```dataview 
TABLE task.text, task.line, meta(task.section)
FROM "Projects"
WHERE !task.completed
SORT task.line
LIMIT 20
```

Doesn’t work.

I thought about TABLE query, but, as I know, it can’t interact with checkboxes. meta(section).subpath doesn’t group.

Maybe only option - renaming headers.

I think it’s so useful - just save the order exactly like in a file, to have opportunity change it at will, but it turned out so difficult.

When not having enough information we can’t help you. So please try to follow suggestions and respond to question asked.

And now I see a typo in my debug script, please try the following and report back the result:

```dataview 
TABLE task.text, task.line, meta(task.section)
FROM "Projects"
FLATTEN file.tasks as task 
WHERE !task.completed
SORT task.line
LIMIT 20
```

Thanks for answer!

In future I will. Sorry for this.

This is what displays meta(task.section) from your example:

display:
embed: false
path: Projects/Project1.md
subpath:
type: file

Table query doesn’t fit - it can’t interact with checkboxes.

Need to sort headers after GROUP BY header by it’s order exactly like in a file. First header in file must bs first header in query.

There is no field called header.

The task you present isn’t placed within a section, as the subpath is empty.

So it’s really hard to understand what you’re trying to achieve. Do you want your query to generate sections and group by them?

How is your kanban generated? The task you present shouldn’t be a part of a pure kanban board, since it’s not within a section.

And yes, I do know you can’t interact with task in a table, and that it’s not what you’re asking for, but it was an attempt to try to understand your data structure, which failed since you seem reluctant presenting any real data related to your setup.

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