drupal tablesort_sql sort by default but don't show in header
I want to create a simple table and make it available for user to sort on the headers. Using the tablesort_sql() function and sending the $header into theme() this can be done easy and nice.
But i want to sort by default on a field that is not visible to the users. as example: I want the content to be sorted by the created date, but i dont want to show that to the users
So here is what I've got:
function vacancies_overview() {
GLOBAL $user;
$header = array(
array('field' => 'created', 'sort' => 'desc'),
array('data' => t('title'), 'field' => 'title'),
);
$sql = "SELECT n.nid, n.title FROM {node} n WHERE n.type = 'mycontenttype' AND n.status = 1 AND n.uid = %d" . tablesort_sql($header);
$result = pager_query($sql, 30, 0, NULL, $user->uid);
while ($data = db_fetch_object($result)) {
$开发者_JAVA百科rows[] = array(
_mycontent_format_title_link($data->title, $data->nid),
);
}
$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 30, 0);
return $output;
}
A quick solution would be to do something like this:
$header = array(
array('field' => 'created', 'sort' => 'desc'),
array('data' => t('title'), 'field' => 'title'),
);
$header_sort = $header;
$header_sort[] = array(...); // Add the default sort.
Then you can use header_sort
for the sql and $header
for the theming of the table.
精彩评论