Change class name view-grid as default if no ?display= in the URL

Fixed the issue of unable to change sort dropdown of Search Result Pager
This commit is contained in:
Kyle Huynh 2021-12-06 20:46:45 +00:00
parent 9836edfb58
commit 8ec130bf8e
2 changed files with 17 additions and 1 deletions

View file

@ -126,7 +126,7 @@ function islandora_advanced_search_preprocess_views_view(&$variables) {
// has been created for.
if (in_array([$view->id(), $view->current_display], $views)) {
// Toggle between 'list' and 'grid' display depending on url parameter.
$format = \Drupal::request()->query->get('display') ?? 'list';
$format = \Drupal::request()->query->get('display') ?? 'grid';
$variables['attributes']['class'][] = "view-{$format}";
$view->element['#attached']['library'][] = 'islandora_advanced_search/advanced.search.pager';
}

View file

@ -132,6 +132,22 @@
window.history.pushState(null, document.title, $(this).attr("href"));
});
/* digitalutsc added */
$('.pager__sort select[name="order"]')
.once()
.change(function () {
var href = window.location.href;
var params = Drupal.Views.parseQueryString(href);
var selection = $(this).val();
var option = selection.split('_');
params.sort_by = option[0];
params.sort_order = option[1].toUpperCase();
href = href.split("?")[0] + "?" + $.param(params);
window.history.pushState(null, document.title, href);
});
// Trigger on sort change.
$('[data-drupal-pager-id] select[name="order"]')