Allow simple pagination option on ListControllers

This commit is contained in:
Jofry S 2017-09-05 13:33:51 +10:00
parent 8a8013e52e
commit 2c97c55ea8
4 changed files with 75 additions and 7 deletions

View File

@ -141,6 +141,7 @@ class ListController extends ControllerBehavior
'recordUrl', 'recordUrl',
'recordOnClick', 'recordOnClick',
'recordsPerPage', 'recordsPerPage',
'showPageNumbers',
'noRecordsMessage', 'noRecordsMessage',
'defaultSort', 'defaultSort',
'showSorting', 'showSorting',
@ -456,7 +457,7 @@ class ListController extends ControllerBehavior
public function listExtendColumns($host) public function listExtendColumns($host)
{ {
} }
/** /**
* Called after the filter scopes are defined. * Called after the filter scopes are defined.
* @param \Backend\Widgets\Filter $host The hosting filter widget * @param \Backend\Widgets\Filter $host The hosting filter widget
@ -559,7 +560,7 @@ class ListController extends ControllerBehavior
call_user_func_array($callback, [$widget, $widget->model]); call_user_func_array($callback, [$widget, $widget->model]);
}); });
} }
/** /**
* Static helper for extending filter scopes. * Static helper for extending filter scopes.
* @param callable $callback * @param callable $callback

View File

@ -96,6 +96,11 @@ class Lists extends WidgetBase
*/ */
public $showPagination = 'auto'; public $showPagination = 'auto';
/**
* @var bool Display page numbers when pagination is enabled
*/
public $showPageNumbers = true;
/** /**
* @var string Specify a custom view path to override partials used by the list. * @var string Specify a custom view path to override partials used by the list.
*/ */
@ -190,6 +195,7 @@ class Lists extends WidgetBase
'recordUrl', 'recordUrl',
'recordOnClick', 'recordOnClick',
'noRecordsMessage', 'noRecordsMessage',
'showPageNumbers',
'recordsPerPage', 'recordsPerPage',
'showSorting', 'showSorting',
'defaultSort', 'defaultSort',
@ -248,6 +254,7 @@ class Lists extends WidgetBase
$this->vars['showCheckboxes'] = $this->showCheckboxes; $this->vars['showCheckboxes'] = $this->showCheckboxes;
$this->vars['showSetup'] = $this->showSetup; $this->vars['showSetup'] = $this->showSetup;
$this->vars['showPagination'] = $this->showPagination; $this->vars['showPagination'] = $this->showPagination;
$this->vars['showPageNumbers'] = $this->showPageNumbers;
$this->vars['showSorting'] = $this->showSorting; $this->vars['showSorting'] = $this->showSorting;
$this->vars['sortColumn'] = $this->getSortColumn(); $this->vars['sortColumn'] = $this->getSortColumn();
$this->vars['sortDirection'] = $this->sortDirection; $this->vars['sortDirection'] = $this->sortDirection;
@ -255,11 +262,15 @@ class Lists extends WidgetBase
$this->vars['treeLevel'] = 0; $this->vars['treeLevel'] = 0;
if ($this->showPagination) { if ($this->showPagination) {
$this->vars['recordTotal'] = $this->records->total();
$this->vars['pageCurrent'] = $this->records->currentPage(); $this->vars['pageCurrent'] = $this->records->currentPage();
$this->vars['pageLast'] = $this->records->lastPage(); if ($this->showPageNumbers) {
$this->vars['pageFrom'] = $this->records->firstItem(); $this->vars['recordTotal'] = $this->records->total();
$this->vars['pageTo'] = $this->records->lastItem(); $this->vars['pageLast'] = $this->records->lastPage();
$this->vars['pageFrom'] = $this->records->firstItem();
$this->vars['pageTo'] = $this->records->lastItem();
} else {
$this->vars['hasMorePages'] = $this->records->hasMorePages();
}
} }
else { else {
$this->vars['recordTotal'] = $this->records->count(); $this->vars['recordTotal'] = $this->records->count();
@ -518,7 +529,10 @@ class Lists extends WidgetBase
$records = $model->getNested(); $records = $model->getNested();
} }
elseif ($this->showPagination) { elseif ($this->showPagination) {
$records = $model->paginate($this->recordsPerPage, $this->currentPageNumber); $paginationMethod = $this->showPageNumbers
? 'paginate'
: 'simplePaginate';
$records = $model->{$paginationMethod}($this->recordsPerPage, $this->currentPageNumber);
} }
else { else {
$records = $model->get(); $records = $model->get();

View File

@ -18,7 +18,11 @@
<?php if ($showPagination): ?> <?php if ($showPagination): ?>
<div class="list-footer"> <div class="list-footer">
<div class="list-pagination"> <div class="list-pagination">
<?php if ($showPageNumbers): ?>
<?= $this->makePartial('list_pagination') ?> <?= $this->makePartial('list_pagination') ?>
<?php else: ?>
<?= $this->makePartial('list_pagination_simple') ?>
<?php endif ?>
</div> </div>
</div> </div>
<?php endif ?> <?php endif ?>

View File

@ -0,0 +1,49 @@
<div class="loading-indicator-container size-small pull-right">
<div class="control-pagination">
<?php if ($pageCurrent > 1): ?>
<a
href="javascript:;"
class="page-first"
data-request="<?= $this->getEventHandler('onPaginate') ?>"
data-request-data="page: 1"
data-load-indicator="<?= e(trans('backend::lang.list.loading')) ?>"
title="<?= e(trans('backend::lang.list.first_page')) ?>"></a>
<?php else: ?>
<span
class="page-first"
title="<?= e(trans('backend::lang.list.first_page')) ?>"></span>
<?php endif ?>
<?php if ($pageCurrent > 1): ?>
<a
href="javascript:;"
class="page-back"
data-request="<?= $this->getEventHandler('onPaginate') ?>"
data-request-data="page: <?= $pageCurrent-1 ?>"
data-load-indicator="<?= e(trans('backend::lang.list.loading')) ?>"
title="<?= e(trans('backend::lang.list.prev_page')) ?>"></a>
<?php else: ?>
<span
class="page-back"
title="<?= e(trans('backend::lang.list.prev_page')) ?>"></span>
<?php endif ?>
<select
disabled
name="page"
class="form-control input-sm custom-select select-no-search">
<option value="<?= $pageCurrent ?>" selected><?= $pageCurrent ?></option>
</select>
<?php if ($hasMorePages): ?>
<a
href="javascript:;"
class="page-next"
data-request-data="page: <?= $pageCurrent+1 ?>"
data-request="<?= $this->getEventHandler('onPaginate') ?>"
data-load-indicator="<?= e(trans('backend::lang.list.loading')) ?>"
title="<?= e(trans('backend::lang.list.next_page')) ?>"></a>
<?php else: ?>
<span
class="page-next"
title="<?= e(trans('backend::lang.list.next_page')) ?>"></span>
<?php endif ?>
</div>
</div>