justinvoelker / yii2-separatedpager
A Yii2 LinkPager that displays the first and last pages inline with other pages.
Installs: 55 241
Dependents: 2
Suggesters: 0
Security: 0
Stars: 30
Watchers: 4
Forks: 16
Open Issues: 1
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2024-11-23 17:27:34 UTC
README
A Yii2 LinkPager that displays the first and last pages inline with other pages.
Rather than having dedicated "First" and "Last" buttons in your LinkPager, Separated Pager will show a standard set of page links but will also always include the first and last pages as the first and last page links. No more dedicated first/last buttons and no more guessing how many pages there are.
Installation
Install the extension
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist justinvoelker/yii2-separatedpager "*"
or add
"justinvoelker/yii2-separatedpager": "*"
to the require section of your composer.json
file.
Usage
Simply add the pager
property to your GridView and reference this class
GridView::widget([ 'dataProvider' => $dataProvider, ... 'pager' => [ 'class' => 'justinvoelker\separatedpager\LinkPager', ] ]);
Please note that specifying less than 7 pages won't produce useful results. Less than 7 pages of content is acceptable (will look like the standard LinkPager) but limiting the pager to something less than 7 pages will look and work poorly. Five pages and the pager is almost worthless. Less than 5 and it is worthless.
Available Options
In addition to all of the standard LinkPager properties, one new property has been added, separator
, that specifies a string to be used to indicate that multiple pages are being omitted. The default separator is ...
.
Here is my preferred pager setup. A max of 7 pages, 'Previous' and 'Next' buttons spelled out that are hidden on extra-small screens.
'pager' => [ 'class' => 'justinvoelker\separatedpager\CustomLinkPager', 'maxButtonCount' => 7, 'prevPageLabel' => 'Previous', 'nextPageLabel' => 'Next', 'prevPageCssClass' => 'prev hidden-xs', 'nextPageCssClass' => 'next hidden-xs', 'activePageAsLink' => false, ]
Keep in mind that setting css classes will overwrite the defaults rather than appending to them. If additional classes should be included (such as the 'hidden-xs' above) the original prev
and next
should be included as well (this is the same way the standard LinkPager functions).
Standard LinkPager functionality uses a link for the active page. By setting activePageAsLink
to false the link can be replaced with a span that looks the same but cannot be clicked.