parent
07d53792c4
commit
5cd371578e
|
@ -5,12 +5,10 @@ function tablesort_init($header) {
|
||||||
static $ts;
|
static $ts;
|
||||||
|
|
||||||
if (empty($ts)) {
|
if (empty($ts)) {
|
||||||
$ts['order'] = tablesort_get_order($header);
|
$ts = tablesort_get_order($header);
|
||||||
$ts['order_sql'] = tablesort_get_order_sql($header, $ts['order']);
|
|
||||||
$ts['sort'] = tablesort_get_sort($header);
|
$ts['sort'] = tablesort_get_sort($header);
|
||||||
$ts['query_string'] = tablesort_get_querystring();
|
$ts['query_string'] = tablesort_get_querystring();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ts;
|
return $ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +20,9 @@ function tablesort_pager() {
|
||||||
|
|
||||||
function tablesort_sql($header) {
|
function tablesort_sql($header) {
|
||||||
$ts = tablesort_init($header);
|
$ts = tablesort_init($header);
|
||||||
return " ORDER BY ". $ts['order_sql']. " ". strtoupper($ts['sort']);
|
$sql = check_query($ts['sql']);
|
||||||
|
$sort = strtoupper(check_query($ts['sort']));
|
||||||
|
return " ORDER BY $sql $sort";
|
||||||
}
|
}
|
||||||
|
|
||||||
function tablesort($cell, $header) {
|
function tablesort($cell, $header) {
|
||||||
|
@ -30,21 +30,20 @@ function tablesort($cell, $header) {
|
||||||
$title = t("sort by %s", array("%s" => $cell['data']));
|
$title = t("sort by %s", array("%s" => $cell['data']));
|
||||||
|
|
||||||
// special formatting for the currently sorted column header
|
// special formatting for the currently sorted column header
|
||||||
if ($cell['data'] == $ts['order']) {
|
if ($cell['data'] == $ts['name']) {
|
||||||
$ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
|
$ts['sort'] = (($ts['sort'] == 'asc') ? 'desc' : 'asc');
|
||||||
$cell['class'] = 'cell-highlight';
|
$cell['class'] = 'active';
|
||||||
$image = ' <img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
|
$image = ' <img src="' . theme('image', 'arrow-' . $ts['sort'] . '.gif') . '" alt="'. t('sort icon') .'" />';
|
||||||
$title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
|
$title = ($ts['sort'] == 'asc' ? t("sort ascending") : t("sort descending"));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// If the user clicks a different header, we want to sort ascending initially.
|
// If the user clicks a different header, we want to sort ascending initially.
|
||||||
$ts['sort'] = "asc";
|
$ts['sort'] = "asc";
|
||||||
}
|
}
|
||||||
|
|
||||||
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&order=". urlencode($cell['data']). $ts['query_string']);
|
$cell['data'] = l($cell['data'] . $image, $_GET['q'], array("title" => $title), "sort=". $ts['sort']. "&order=". urlencode($cell['data']). $ts['query_string']);
|
||||||
|
|
||||||
unset($cell['field']);
|
unset($cell['field'], $cell['sort']);
|
||||||
unset($cell['sort']);
|
|
||||||
|
|
||||||
return $cell;
|
return $cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +61,11 @@ function tablesort_get_order($headers) {
|
||||||
$order = $_GET['order'];
|
$order = $_GET['order'];
|
||||||
foreach ($headers as $header) {
|
foreach ($headers as $header) {
|
||||||
if ($order == $header['data']) {
|
if ($order == $header['data']) {
|
||||||
return $header['data'];
|
return array('name' => $header['data'], 'sql' => $header['field']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
|
if ($header['sort'] == 'asc' || $header['sort'] == 'desc') {
|
||||||
$default = $header['data'];
|
$default = array('name' => $header['data'], 'sql' => $header['field']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,15 +74,11 @@ function tablesort_get_order($headers) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// The first column specified is initial 'order by' field unless otherwise specified
|
// The first column specified is initial 'order by' field unless otherwise specified
|
||||||
$first = reset($headers);
|
if (is_array($headers[0])) {
|
||||||
return $first['data'];
|
return array('name' => $headers[0]['name'], 'sql' => $headers[0]['field']);
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
|
return array('name' => $headers[0]);
|
||||||
function tablesort_get_order_sql($header, $order) {
|
|
||||||
foreach ($header as $cell) {
|
|
||||||
if ($cell['data'] == $order) {
|
|
||||||
return $cell['field'];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,6 +318,7 @@ function theme_table($header, $rows, $attributes = NULL) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (is_array($header)) {
|
if (is_array($header)) {
|
||||||
|
$ts = tablesort_init($header);
|
||||||
$output .= " <tr>";
|
$output .= " <tr>";
|
||||||
foreach ($header as $cell) {
|
foreach ($header as $cell) {
|
||||||
if (is_array($cell) && $cell['field']) {
|
if (is_array($cell) && $cell['field']) {
|
||||||
|
@ -343,16 +344,12 @@ function theme_table($header, $rows, $attributes = NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($row as $cell) {
|
foreach ($row as $cell) {
|
||||||
// highlight the currently sorted column. only applies to tables with headers.
|
if ($header[$i]['data'] == $ts['name'] && $header[$i]['field']) {
|
||||||
if (is_array($header)) {
|
if (is_array($cell)) {
|
||||||
$ts = tablesort_init($header);
|
$cell['class'] .= ' active';
|
||||||
if ($i === $ts['index']) {
|
}
|
||||||
if (is_array($cell)) {
|
else {
|
||||||
$cell['class'] = 'active';
|
$cell = array('data' => $cell, 'class' => 'active');
|
||||||
}
|
|
||||||
else {
|
|
||||||
$cell = array('data' => $cell, 'class' => 'active');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$output .= _theme_table_cell($cell, 0);
|
$output .= _theme_table_cell($cell, 0);
|
||||||
|
@ -364,7 +361,6 @@ function theme_table($header, $rows, $attributes = NULL) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$output .= "</table>\n";
|
$output .= "</table>\n";
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ tr.light {
|
||||||
tr.dark td, tr.light td {
|
tr.dark td, tr.light td {
|
||||||
padding: 0.1em 0.6em;
|
padding: 0.1em 0.6em;
|
||||||
}
|
}
|
||||||
|
th.active img {
|
||||||
|
display: inline;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Menu styles
|
** Menu styles
|
||||||
|
|
Loading…
Reference in New Issue