Feature: #94625 - Introduce sliding window pagination

See Issue #94625

Description

Since TYPO3 10 a new Pagination API is shipped, which supersedes the pagination widget controller, which had been removed in TYPO3 11.

This patch provides an improved pagination which can be used to paginate array items or query results from Extbase. The main advantage is that it reduces the amount of pages shown.

Example: Imagine 1000 records and 20 items per page which would lead to 50 links. Using the SlidingWindowPagination, you will get something like < 1 2 ... 21 22 23 24 ... 100 >.

Usage

Just replace the usage of SimplePagination with \TYPO3\CMS\Core\Pagination\SlidingWindowPagination and you are done. Set the 2nd argument to the maximum number of links which should be rendered.

$currentPage = $this->request->hasArgument('currentPage')
   ? (int)$this->request->getArgument('currentPage')
   : 1;
$itemsPerPage = 10;
$maximumLinks = 15;

$paginator = new \TYPO3\CMS\Extbase\Pagination\QueryResultPaginator(
   $allItems,
   $currentPage,
   $itemsPerPage
);
$pagination = new \TYPO3\CMS\Core\Pagination\SlidingWindowPagination(
   $paginator,
   $maximumLinks
);

$this->view->assign(
   'pagination',
   [
      'pagination' => $pagination,
      'paginator' => $paginator
   ]
);

Credits

This patch is loosely based on the “numbered_pagination” extension by Georg Ringer.

Thanks to him.