@@ -188,17 +188,13 @@ class DashboardPanelCollection extends DashboardPanel
188188 // Buttons (add new)
189189 $buttons = $this->renderFooterButtons();
190190 if ($buttons) {
191- $footer .= "<div>{$buttons}</div>";
191+ $footer .= "<div class='DashboardFooterButtons' >{$buttons}</div>";
192192 }
193193
194194 // Pagination
195- if ($this->pagination && $this->collection->hasPagination()) {
196- $pagination = sprintf(
197- $this->_('Showing %d of %d'),
198- $this->collection->count,
199- $this->collection->getTotal()
200- );
201- $footer .= "<div>{$pagination}</div>";
195+ if ($this->supportsPagination()) {
196+ $pagination = $this->renderPaginationPager($this->collection);
197+ $footer .= "<div class='DashboardFooterPagination'>{$pagination}</div>";
202198 }
203199
204200 return $footer ? "<div>{$footer}</div>" : '';
@@ -256,15 +252,9 @@ class DashboardPanelCollection extends DashboardPanel
256252 }
257253 }
258254
259- // Update collection after changes
260- // e.g. when pages trashed
255+ // Update collection after changes, e.g. when pages trashed
261256 if ($changed) {
262- if ($this->collection instanceof PageArray) {
263- $selectors = $this->collection->getSelectors();
264- if ($selectors) {
265- $this->collection = $this->pages->find($selectors, ['cache' => false]);
266- }
267- }
257+ $this->refetchCollection();
268258 }
269259 }
270260
@@ -308,11 +298,80 @@ class DashboardPanelCollection extends DashboardPanel
308298
309299 if ($this->config->ajax) {
310300 $this->executeAjaxActions();
301+ $this->refetchCollectionForPagination();
311302 }
312303
313304 return true;
314305 }
315306
307+ protected function supportsPagination()
308+ {
309+ return (
310+ $this->pagination &&
311+ $this->collection instanceof PageArray &&
312+ $this->collection->hasPagination() &&
313+ $this->collection->getSelectors()
314+ );
315+ }
316+
317+ protected function refetchCollection()
318+ {
319+ if (!($this->collection instanceof PageArray)) {
320+ return;
321+ }
322+
323+ /** @var \ProcessWire\Selectors $selectors */
324+ $selectors = $this->collection->getSelectors();
325+ if (!$selectors) {
326+ return;
327+ }
328+
329+ $this->collection = $this->pages->find($selectors, ['cache' => false]);
330+ }
331+
332+ protected function refetchCollectionForPagination()
333+ {
334+ if (!$this->config->ajax) return;
335+ if (!$this->supportsPagination()) return;
336+
337+ $this->wire()->input->setPageNum($_POST['page'] ?? 1);
338+ $this->refetchCollection();
339+ }
340+
341+ protected function renderPaginationSummary(PageArray $items)
342+ {
343+ return sprintf(
344+ $this->_('Showing %d of %d'),
345+ $items->count,
346+ $items->getTotal()
347+ );
348+ }
349+
350+ protected function renderPaginationPager(PageArray $items)
351+ {
352+ /** @var \ProcessWire\MarkupPagerNav $pager */
353+ $pager = $this->wire()->modules->get('MarkupPagerNav');
354+
355+ $summary = $items->getPaginationString();
356+ $pagination = $pager->render($items, [
357+ 'numPageLinks' => 3,
358+ 'listClass' => 'uk-pagination',
359+ 'listMarkup' => "<ul class='uk-pagination DashboardPagination'>{out}</ul>",
360+ 'linkMarkup' => "<a href='{url}' data-pagination>{out}</a>",
361+ 'currentItemClass' => 'uk-active',
362+ 'separatorItemLabel' => '<span>…</span>',
363+ 'separatorItemClass' => 'DashboardPaginationSeparator',
364+ 'currentLinkMarkup' => "<a href='{url}' data-pagination>{out}</a>",
365+ 'nextItemLabel' => '<i class="fa fa-angle-right"></i>',
366+ 'previousItemLabel' => '<i class="fa fa-angle-left"></i>',
367+ 'nextItemClass' => '',
368+ 'previousItemClass' => '',
369+ 'lastItemClass' => '',
370+ ]);
371+
372+ return "<div>{$summary}</div> {$pagination}";
373+ }
374+
316375 /**
317376 * Render footer buttons
318377 * Taken from PageLister, so it should work for most cases.
0 commit comments