Sort dataview field alphabetically

What I’m trying to do

Hello, I’m still new at dataview, and still struggle a bit to get thinks working by my own.
i got a little note where I just keep definitions of random words that I like or find inspiring.
since it starts to grow, I’m trying to automatically order them using dataview.
I been doing things like this :

Things I have tried

1. (word::**word**) : definition of the word.

i added list numbers (1. 2. 3. , etc) in front of each one of them, and created the (word::slight_smile: field

then I been writing something like this :

    "Des jolis"

but for now I have a “Dataview: No results to show for list query.” answer.

no need to say i’m not exactly sure of what I’m doing

Let’s say we have a file Des jolis with a list of words like:

Des jolis

1. (word::**one**): (definition:: Word definition).
2. (word::**two**): (definition:: Word definition).
3. (word::**three**): (definition:: Word definition).

Note that I included an inline field for the definition.

We can add this query to pull the list sorted by word:

LIST WITHOUT ID L.word + ": " + L.definition
FROM "Des jolis mots"
FLATTEN file.lists as L


one: Word definition
three: Word definition
two: Word definition

Our query is flattening the array which contains the lists of the note file.lists and then sortering by word with SORT L.word ASC. For the output we first skip the link of the file, by using WITHOUT ID and the we concatenate the inline fields word: definition using L.word + ": " + L.definition.

Alternatively, if you want to group by word, you can do this:

LIST rows.L.definition
FROM "Des jolis mots"
FLATTEN file.lists as L
GROUP by L.word


- one:
  - Word definition
- three:
  - Word definition
- two:
  - Word definition

By the way, if you just have a list of words and you want to add one at the end, from time to time, but keep your list ordered alphabetically, there’s also a manual approach (I’m not saying that this approach is better, but just to show you some possibilities).

Using the Sort and Permut Plugin you can order the list each time you add a word.

Lett’s say this is your list:

- Pomme: Fruit comestible produite par un pommier.
- Chat: Petit mammifère carnivore domestiqué.
- Soleil: Étoile au centre de notre système solaire.
- Livre: Œuvre écrite ou imprimée constituée de pages.
- Montagne: Grande formation terrestre s'élevant de manière prominente.
- Jardin: Espace extérieur cultivé pour des plantes, des fleurs ou des légumes.
- Vélo: Véhicule propulsé par la force humaine avec deux roues.
- Étoile: Corps céleste lumineux visible dans le ciel nocturne.
- Poisson: Vertébré aquatique à sang froid avec des branchies et des nageoires.
- Chapeau: Couvre-chef porté à des fins diverses.

And with the plug installed you open the command palette ctrl + p and search for Sort alphabetically, hit Enter and Voilà, the list is sorted!



1 Like

thanks a lot.

have to say that the second solution looks a lil’ bit simpler and quick.
(also, love that the exemple is in french here ;).

and, just out of curiosity, the two solutions you gave me for dataview are acting weirdly.

i typed this or the second one

LIST WITHOUT ID L.word + ": " + L.definition
FROM "vrac/Des jolis mots"
FLATTEN file.lists as L

but :
1- I had to add some

0. (word::) (definition::)

kind of empty field

because otherwise it gives me this weird result in reading mode :

1. (word::**Sourdre**): (def::naître, sortir de la terre.)
2. (word::**Haptique**): (def::qui concerne le sens du toucher (par opp. à **optique**). Idée de la tension entre vision et sensations tactiles face une oeuvre, à la tension proche/lointain, ensemble/détail, etc.)
3. (word::**Entropie**/**homéostasie**): (def::tension entre le désagregement, la dislocation, l’éparpillement d’une forme, d’un organisme (**entropie**) et sa préservation, son maintient, sa perduration dans le temps (**homéostasie**))
4. (word::**Empan**): (def::ancienne mesure de longueur (main ouverte, de l’extrémité du pouce au petit doigt). Au sens figuré : **ampleur, envergure**)
5. (word::**Inextinguible**): (def::qu’il est impossible d’éteindre, de satisfaire, de combler)
6. (word::**Truisme**): (def::(*synonyme de **lapalissade***) affirmer une évidence immédiatement perceptible vient de l'anglais *true*.)
Sourdre: naître, sortir de la terre.
Sourdre: naître, sortir de la terre.
Sourdre: naître, sortir de la terre.
Sourdre: naître, sortir de la terre.
Sourdre: naître, sortir de la terre.
Sourdre: naître, sortir de la terre.
Sourdre : sensibilité au mouvement.

as if it replaces all the words by the first one of the list

it also adds 3 or 4 empty rows for now reasons at the top of the list. not a big deal, but not eastheticaly pleasant.

still, thanks a lot for your help !

Yeah that’s what we discussed before in another post. It’s a bug.

But if you are adding some random item at the start of the list as a workaround for the bug, you can adjust the query to retrieve only the list items with a word, by adding WHERE L.word:


1. My list of words:
2. (word::**one**): (definition:: Word definition).
3. (word::**two**): (definition:: Word definition).
4. (word::**three**): (definition:: Word definition).


LIST WITHOUT ID L.word + ": " + L.definition
FROM "Words"
FLATTEN file.lists as L
WHERE L.word


- one: Word definition
- three: Word definition
- two: Word definition

Please remember to mark a post as a solution if you think your question was solved. Thanks.

yeah, yeah I remembered.

just wanted to notified it, so it maybe be usefull to some ppl encoutering the same problem.

just because I’m trying to improve myself, what does the “L” stand for in the code, when you’re using it in “L.word” for example ?

otherwise, things are solved, thanks for your help once again

file.lists is an array that contains a list of all the lists elements, that means that to access the values inside the array (as “one: Word definition”, 'three: Word definition") we must retrieve the values one by one, that’s what flatten does, it returns a row for each element of the array, to help you to operate with nested lists.

Besides the arrray that you want to “flat” or “unfold”, flatten allows you to add a name FLATTEN (computed_field) AS name, an “alias” that you can use to reference the flattened data in other parts of your query.

I use L as an abbreviation of List, but it can be whatever you prefer:

FLATTEN file.lists as myWord
WHERE myWord.word
SORT myWord.word ASC
FLATTEN file.lists as listofwords
WHERE listofwords.word
SORT listofwords.word ASC
1 Like

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