TableSort issue with expressions

Created on 24 September 2010, over 14 years ago
Updated 24 January 2025, 4 months ago

I found this problem when using theme_table() to create a sortable table from a query that uses db_select's addExpression() method. It should output a 3 column table. The middle column's content should be the alias created by addExpression(). Instead, the content always ends up in the last column of the table, no matter what.

<!--break-->

I have tried this with any number of columns, and any alias added by addExpression() always ends up at the right-hand side of the table. I don't know if this is a problem with db_select or theme_table().

Details on my platform: PHP 5.2.14, PostgreSQL 8.3.11, Apache2 2.2.11

Sample code:

  // $headers for theme_table and TableSort extender
  $headers = array(
    array( 'data' => 'Manufacturer', 'field' => 'company_name', 'sort' => 'asc' ),  // FIRST column
    array( 'data' => 'Item', 'field' => 'itemlink'),  // SECOND column
    array( 'data' => 'Abbr.', 'field' => 'abbreviation')  // THIRD column
  );

  // Set up the query
  $query = db_select('battery_model_list_view');
  $query = $query->extend('TableSort');
  $query = $query->orderByHeader($headers); 
  $query->addField('battery_model_list_view', 'company_name');  // FIRST db column
  $query->addExpression("'<a href=\"/batt/details/' || batt_model_id ||'\">' || model || '</a>'", 'itemlink');  // SECOND db column
  $query->addField('battery_model_list_view', 'abbreviation');  // THIRD db column

  // Execute the query
  $result = $query->execute();
  $rows = $result->fetchAll(PDO::FETCH_ASSOC);
 
// Create $table variables for theme_table()
  $table = array(
    'header' => $headers,
    'rows' => $rows,
    'caption' => null,
    'attributes' => array(),
    'colgroups' => array(),
    'sticky' => null,
    'empty' => null,
  );

   $out = "<p>The following is a list of items.  Click the model to see details of that model</p>";
 
  $out .= theme_table($table);
 
  return $out;
πŸ› Bug report
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

database system

Created by

πŸ‡ΊπŸ‡ΈUnited States JohnWoltman

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

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.

  • πŸ‡³πŸ‡ΏNew Zealand luke.stewart

    Found this at the end of the bug smash "Needs issue summary update" queue.
    Looks like it got this take with a question as to whether this was still an issue in D8.
    There was no response.
    Given that and there has been a good 6 years since last comment. I'm going to mark as postponed needs info.
    I think if there is no engagement in another 6 months then we can probably close this.

  • Status changed to Closed: outdated 20 days ago
  • πŸ‡¦πŸ‡ΊAustralia acbramley

    Given the lack of updates here I'm going to close this one out.

    Please feel free to reopen with an updated issue summary including steps to reproduce if this still affects you.

Production build 0.71.5 2024