I noticed this last week in 4.6.x and it's still here in 4.7.0.

When building a sortable table/pager with theme_pager, the array elements 'data' and 'field' are getting mismatched.
It seems the tablesort wants to sort the table using the data field as well as using this for display (the 'field' element doesn't appear to get referenced?!).

Anyhow, here's my fix (sorry it's not a patch):
file: tablesort.inc
line: 77
orig. code:

$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']) .'&'. $ts['query_string'], NULL, FALSE, TRUE);

changed code:

$cell['data'] = l($cell['data'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['field']) .'&'. $ts['query_string'], NULL, FALSE, TRUE);

Comments

fronbow’s picture

After further inspection, the above is wrong.

the line should be changed to

$cell['data'] = l($cell['field'] . $image, $_GET['q'], array('title' => $title), 'sort='. $ts['sort'] .'&order='. urlencode($cell['data']). $ts['query_string'], NULL, FALSE, TRUE);
?>

It's the initial cell that's wrong (1st one inside the link).

magico’s picture

Version: 4.7.0 » x.y.z
Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)
mandclu’s picture

Version: x.y.z » 5.1

I'm seing this same behaviour in 5.1. Was this actually fixed in the core code?

danielnolde’s picture

Version: 5.1 » 5.17
Status: Closed (fixed) » Active

I just run accross the same bug, according to Drupal API Docs this still is buggy and NOT fixed for D5, D6 *and* D7. This is really a bug and *not* in line with the specification of table header parameter usage, see
http://api.drupal.org/api/function/theme_table

The plain trivial proposed here is correct, applied in seconds and works for for all versions.

Please commit/include.

bradweikel’s picture

Version: 5.17 » 7.x-dev

Don't know anything about this issue, but it looks like it needs to be checked in D7 first and then backported if it gets fixed.

aspilicious’s picture

In drupal 7 I can't find that specific line anymore, so I don't think this is a drupal 7 problem

berdir’s picture

Status: Active » Closed (won't fix)

This is not a bug.

data is used to not expose the internal field name. Internally, field is then used to do the actual query.

The code in D7 looks like this:

    $order = isset($_GET['order']) ? $_GET['order'] : '';
    foreach ($this->header as $header) {
      if (isset($header['data']) && $order == $header['data']) {
        return array('name' => $header['data'], 'sql' => isset($header['field']) ? $header['field'] : '');
      }

As you can see, it compares the data value but then uses field for the 'sql' key, which is then used in the ORDER BY. Also, this code hasn't changed since 4.6 except for being E_NOTICE free: http://api.drupal.org/api/function/tablesort_get_order/4.6

Setting to won't fix.