In Drupal 8 I have View formatted as table, where user can click to any column header to sort displayed records according to the given field. This works well for numbers (ascending/descending), as well as for plain text (ascending/descending for title or any other text values), records are then sorted correctly alphabetically. But this does not work for taxonomy terms - they are sorted according to taxonomy term ID and not alphabetically according to label.

I.e. I wish to display in the table column with a taxonomy term (only one value is allowed per node) and be able to sort the table alphabetically.

In my use case I have records about plant specimens containing plenty of fields, including e.g. species or life form. These are taxonomy terms. I'm displaying the specimen records in table filterable according to various criteria, e.g. various traits. The table is also sortable according to any column, e.g. species, but in this particular case, it is sorted according to taxonomy term ID and not naturally by label.

I found several answers to similar problems, but nothing exactly fitting my problem. Views Natural Sort module might also help, but its development status is not very promising.

1 Answer 1


That's because the stored value of the field is the term ID, the label of it is just how it is displayed.

To sort on the name, you need to instead add a relationship using that field to terms, and then add the name field of that relationship. Then you should be able to sort it as well based on that.

  • Thank you. I followed drupal.org/docs/8/core/modules/views/…, but I wasn't successful. I can add relatioship to e.g. Taxonomy term referenced from field_life_form, but it doesn't add anything new when adding new Field, neither to respective options (Field Content: Life form (Life form)). So that the result is unchanged. Am I missing some critical point?
    – Tilia
    Commented Aug 5, 2018 at 14:04
  • There should be a "Name" field for example in the new "Taxonomy term" or maybe just "Term" group.
    – Berdir
    Commented Aug 6, 2018 at 16:42
  • Ah, thank you. This wasn't very obvious, I overlooked that.
    – Tilia
    Commented Aug 7, 2018 at 7:04
  • Funny enough this relationship then has to be added to all displays, see #2921276.
    – leymannx
    Commented Mar 13, 2020 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.