[SOLVED] Sort alphabetically

I have this query:

#+BEGIN_QUERY
{:title [:h3 "Words"]
 :query [:find (pull ?b [*])
  :where
   [?b :block/properties ?prop]
   [(get ?prop :topic) ?topic]
   [(= ?topic "vocab")]
 ]
 :remove-block-children? false
}
#+END_QUERY

which gives me a list of words, like so:
==House==: place where on lives
==Dog==: animal, pet

Is it possible to sort the list alphabetically on the basis of the 1st word in each phrase?
So, the list would look like this:

==Dog==: animal, pet
==House==: place where on lives

Do you mean to sort by Dog and House?
Then you just need to sort by block content.

#+BEGIN_QUERY
{:title [:h3 "Words"]
 :query [:find (pull ?b [*])
  :where
   [?b :block/properties ?prop]
   [(get ?prop :topic) ?topic]
   [(= ?topic "vocab")]
 ]
 :result-transform (fn [result] (sort-by (fn [r] (get r :block/content)) result))
 :remove-block-children? false
}
#+END_QUERY

Yep, that is exactly what I was looking for. Many thanks for that.

Last question in this context:

image

block and topic are vertically aligned with the text below them, but page is not, which is odd. Can vertical alignment be done for page, or is it a Logseq quirk?

Quirk of your theme actually. Default Logseq result tables don’t break lines apparently :open_mouth:

I don’t know about your theme, but I use some custom css in my personal graph

table th, 
table td {
	white-space: normal !important;
	overflow-wrap: normal;
	word-break: normal;
}

It will then look like this:

Thanks. It is not a quirk, but this in my custom.css:

table td:nth-child(2) {
  text-align: center;
}

table th:nth-child(2) {
  text-align: center;
}

which I had because text in “regular” tables was only centered in some columns.
When I disabled this snippet the page header was aligned again. I still find it odd that only the page header was out of kilter, but that is not important.

What counts is the solution, and you provided it.
Many thanks for your help and time!

1 Like