Skip to content

Commit

Permalink
Merge branch 'MDL-69201' of https://github.com/paulholden/moodle into…
Browse files Browse the repository at this point in the history
… master
  • Loading branch information
stronk7 committed Nov 18, 2020
2 parents 3492cf8 + 70936e0 commit 30f2fe5
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/tablelib.php
Expand Up @@ -1201,6 +1201,12 @@ protected function show_hide_link($column, $index) {
function print_headers() {
global $CFG, $OUTPUT;

// Set the primary sort column/order where possible, so that sort links/icons are correct.
[
'sortby' => $primarysortcolumn,
'sortorder' => $primarysortorder,
] = $this->get_primary_sort_order();

echo html_writer::start_tag('thead');
echo html_writer::start_tag('tr');
foreach ($this->columns as $column => $index) {
Expand All @@ -1209,14 +1215,6 @@ function print_headers() {
if ($this->is_collapsible) {
$icon_hide = $this->show_hide_link($column, $index);
}

$primarysortcolumn = '';
$primarysortorder = '';
if (reset($this->prefs['sortby'])) {
$primarysortcolumn = key($this->prefs['sortby']);
$primarysortorder = current($this->prefs['sortby']);
}

switch ($column) {

case 'fullname':
Expand Down Expand Up @@ -1596,6 +1594,22 @@ protected function sort_link($text, $column, $isprimary, $order) {
]) . ' ' . $this->sort_icon($isprimary, $order);
}

/**
* Return primary sorting column/order, either the first preferred "sortby" value or defaults defined for the table
*
* @return array
*/
protected function get_primary_sort_order(): array {
if (reset($this->prefs['sortby'])) {
return $this->get_sort_order();
}

return [
'sortby' => $this->sort_default_column,
'sortorder' => $this->sort_default_order,
];
}

/**
* Return sorting attributes values.
*
Expand Down

0 comments on commit 30f2fe5

Please sign in to comment.