- πΊπΈUnited States erutan
I've come across the issue in a standard table and a table using aggregation. I have a very simple math field "outstanding" (amount - paid) that it'd be nice to sort by since most of them are 0. No pagination. I get the following error on Drupal 9.5.10, I'm using storage (contrib) entity types but I'm not sure why that would impact things.
The website encountered an unexpected error. Please try again later.
Drupal\Core\Database\DatabaseExceptionWrapper: Exception in Purchase Order - Invoices[purchase_order_invoices]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_views_simple_math_field' in 'order clause': SELECT "storage_field_data"."id" AS "id" FROM "storage_field_data" "storage_field_data" WHERE ("storage_field_data"."status" = :db_condition_placeholder_0) AND ("storage_field_data"."type" IN (:db_condition_placeholder_1)) ORDER BY "field_views_simple_math_field" ASC; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => wildlife_purchase_order ) in main() (line 19 of index.php).
- πΊπΈUnited States andileco
Sorry for the delay. So views_simple_math_field does not store any data in the database, so anything that tries to use a query, like using the "sort" feature in a table display, will cause an error. Instead, please use the "Sort" plugin (via the "Sort Criteria" section). I do realize this will not work for all use-cases, but this should help for some.
- πͺπΈSpain prodigia Malaga
I attempted to achieve this using Sort Criteria, but for some reason, it is not arranging properly.
- First commit to issue fork.
- πΊπΈUnited States erutan
Sorry for the even longer delay. :)
Using the views sort feature works great for a static display (or one that can be changed via exposing the filter). Having the UI to select which specific simple math field by label is convenient. My use case was for a tabular view of data where the simple math field wasn't the default sort option, but could be one that someone would be interested in sorting by.
I could just have an exposed filter for the sort, but then the UI is split up between using it and clicking on a TH. I could also have it default it to sort on the simple math field, then let people override it with the built in table sort, but then they'd need to refresh to get back to it. Hmmm. Or just leave that field unsortable. :p
I presume there'd be some way to hijack the sort for a specific field in a table display to toggle the sort criteria, but that seems janky. I suppose keeping this open helps people find it, but it feels more like a closed (working as designed).