8.5.x tablesort.inc tablesort_get_order($headers)
8.0.x tablesort.inc tablesort_get_order($headers)
8.1.x tablesort.inc tablesort_get_order($headers)
8.2.x tablesort.inc tablesort_get_order($headers)
8.3.x tablesort.inc tablesort_get_order($headers)
8.4.x tablesort.inc tablesort_get_order($headers)
8.6.x tablesort.inc tablesort_get_order($headers)
4.6.x tablesort.inc tablesort_get_order($headers)
4.7.x tablesort.inc tablesort_get_order($headers)
5.x tablesort.inc tablesort_get_order($headers)
6.x tablesort.inc tablesort_get_order($headers)
7.x tablesort.inc tablesort_get_order($headers)

Determines the current sort criterion.

Parameters

$headers: An array of column headers in the format described in theme_table().

Return value

An associative array describing the criterion, containing the keys:

  • "name": The localized title of the table column.
  • "sql": The name of the database field to sort on.
3 calls to tablesort_get_order()
EntityFieldQuery::tableSort in includes/entity.inc
Enables sortable tables for this query.
TableSort::order in includes/tablesort.inc
Determine the current sort criterion.
tablesort_init in includes/tablesort.inc
Initialize the table sort context.

File

includes/tablesort.inc, line 204
Functions to aid in the creation of sortable tables.

Code

function tablesort_get_order($headers) {
  $order = isset($_GET['order']) ? $_GET['order'] : '';
  foreach ($headers as $header) {
    if (is_array($header)) {
      if (isset($header['data']) && $order == $header['data']) {
        $default = $header;
        break;
      }
      if (empty($default) && isset($header['sort']) && ($header['sort'] == 'asc' || $header['sort'] == 'desc')) {
        $default = $header;
      }
    }
  }
  if (!isset($default)) {
    $default = reset($headers);
    if (!is_array($default)) {
      $default = array(
        'data' => $default,
      );
    }
  }
  $default += array(
    'data' => NULL,
    'field' => NULL,
  );
  return array(
    'name' => $default['data'],
    'sql' => $default['field'],
  );
}