1

Table field 'Manufacturer' is set to sort by ascending or descending and when you sort it. At first it looks like it's sorting by alphabet, it starts with A, B, C etc. but eventually ends up with A again at the bottom?

enter image description here

The Manufacturer field is a taxonomy term. I can recreate that on a new view just with this field and it still won't sort. Title field sorts fine.

update Looks like you can't sort a taxonomy term alphabetically in a Table View, to reproduce that just create a random view for a content type that has a random taxonomy field that is limited to 1, so you can enable Sort in the Table settings. And if you try to sort, it makes no sense, not alphabetical at all.

1
  • As a workaround I ended up using 3rd party jQuery library DataTables which works really good, light fast too. Jun 3, 2020 at 13:43

2 Answers 2

1

Taxonomy term fields are entity reference fields. They only store the reference to the entity, which usually a number that is the ID for that entity. In case of Taxonomy the reference fields store the TID (taxonomy term ID) which is the number you can see in the path when you edit the term in the admin area.

When you sort your table using the reference field, it will follow the number sort of the term IDs.

But you want to sort alphabetically using term names.

Term names aren't stored in node tables in the database, taxonomy module has its own tables. You have to pull the term data into your node views in order to use it as a sorting criteria.

To pull related data into views use Relationships.

In your case you have to add the Relationship for the Manufacturer taxonomy term field. After you add that Relationship you will be able to add a new field to your views called Taxonomy term: Name. You will be able to sort your table using that field, and the results will be sorted alphabetically!

Remove your original Manufacturer field if you don't need it for anything else, the Term name field should be able to work as a full replacement while also providing the alphabetic sort criteria.

0

For what it's worth, I had the same problem with a View in a Drupal 9 installation.

All I had to do was add the relation to the term field under Advanced (Taxonomy term referenced from field_my_taxonomy_field) and save the view.

Et viloa! Now the sort was OK on the existing term field picked from the content type - which sorted totally crazy before.

Martin

Your Answer

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

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