Sorting column doesn't work (SQL error) [working as designed, here for FYI now]

Created on 21 April 2023, over 1 year ago
Updated 7 February 2024, 11 months ago

Problem/Motivation

Thank you for this wonderful module. It would be great if I could sort the Simple Math Field column in a table. But if I try, view gives me the following SQL error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'field_views_simple_math_field' in 'order clause': SELECT "node_field_data"."langcode" AS "node_field_data_langcode", "node_field_data"."nid" AS "nid" FROM "node_field_data" "node_field_data" ORDER BY "field_views_simple_math_field" DESC LIMIT 10 OFFSET 0; Array ( )

Steps to reproduce

1. Create a view with table format
2. add 2 fields with number
3. add Simple Math Field to calculate the two previous fields
4. go to table settings > default sorting on the Simple Math Field
OR
4. make the Simple Math Field column sortable, display the view as page and try to sort the column by clicking on the header of that column

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany bobjoe

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡Έ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).

  • πŸ‡ΊπŸ‡ΈUnited States erutan
Production build 0.71.5 2024