For Drupal 6 you could do something like this:
$header = array(
array('data' => t('Order id'), 'field' => 'order_id'),
...
array('data' => t('Transaction time'), 'field' => 'payment_time', 'sort' => 'desc'),
);
$sql = "...";
$sql .= tablesort_sql($header);
$limit = 25;
$result = pager_query($sql, $limit);
...
I took a look and for drupal 7 and both pager_query
and tablesort_sql
is now gone. It seems that instead the PagerDefault
class can be used to create a pager query using DBTNG. I wasn't able to find any clues on a simple API for attaching a sortable table to the query like it is done in Drupal 6.
So how do you create a sortable table with a pager pulling data from a custom table?