0

I'm displaying a table of dated items ordered from old to new and am using the full pager. How can I force my page to initially display those items that are current ie. on initial load, display the page containing items that are most current (which might be ?page=17). The user can then page back/forwards to get older or newer items. Drupal 8.

0

I'm half way there!

In hook_views_pre_build(\Drupal\views\ViewExecutable $view) I figured that the $cnt item was the most current; from there it was a simple matter to calculate which page that item would appear on and to set that as the current page.

$pager = $view->getPager();
$defaultPageNum = round($cnt/$pager->getItemsPerPage());
$pager->setCurrentPage($defaultPageNum);

This works like a charm; however, the pager links at the bottom of the page do not auto-magically update and still indicate that I'm on page 1 (instead of page 62).

Anyone know how I get these links to update?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.