kop/yii2-scroll-pager

Infinite AJAX scrolling for Yii2 ListView widget

Installs: 571 971

Dependents: 14

Suggesters: 0

Security: 0

Stars: 180

Watchers: 19

Forks: 63

Open Issues: 47

Type:yii2-extension

2.7.2 2020-07-08 07:52 UTC

This package is auto-updated.

Last update: 2024-11-08 17:24:45 UTC


README

Yii2 Scroll Pager (Y2SP) turns your regular paginated page into an infinite scrolling page using AJAX.

Y2SP works with a Pagination object which specifies the totally number of pages and the current page number.

Pager is build with help of JQuery Infinite Ajax Scroll plugin.

Latest Stable Version Code Climate Scrutinizer Code Quality Dependency Status License

Requirements

  • Yii 2.0
  • PHP 5.4

Installation

The preferred way to install this extension is through Composer.

Either run

php composer.phar require kop/yii2-scroll-pager "dev-master"

or add

"kop/yii2-scroll-pager": "dev-master"

to the require section of your composer.json file.

Usage

Just pass the ScrollPager class name to the ListView pager configuration. Make sure that items in your list have some classes that can be used as JavaScript selectors.

ListView

echo ListView::widget([
     'dataProvider' => $dataProvider,
     'itemOptions' => ['class' => 'item'],
     'itemView' => '_item_view',
     'pager' => ['class' => \kop\y2sp\ScrollPager::className()]
]);

ListView (Advanced example)

Here you can see how you can use variable {{ias}} for events. In this example are added the new settings linkPager, linkPagerOptions and linkPagerWrapperTemplate.

echo ListView::widget([
     'options' => ['class' => 'list-view'],
     'dataProvider' => $listDataProvider,
     'itemOptions' => ['tag' => false],
     'itemView' => '_list_item',
     'summary' => '',
     'layout' => '{items}{pager}',
     'pager' => [
          'class' => \kop\y2sp\ScrollPager::className(),
          'item' => 'article',
          'next' => '.next a',
          'paginationSelector' => '.list-view .pagination',
          'triggerText' => Yii::t('app', 'Show more'),
          'triggerTemplate' => '<span class="reveal-btn">{text}</span>',
          'noneLeftText' => '',
          'noneLeftTemplate' => '',
          'spinnerSrc' => '',
          'spinnerTemplate' => '',
          'linkPager'     => [
               'prevPageCssClass' => 'btn-link prev',
               'nextPageCssClass' => 'btn-link next',
               'prevPageLabel' => '<span class="prev-page">prev</span>',
               'nextPageLabel' => '<span class="next-page">next</span>',
          ],
          'linkPagerOptions'     => [
               'class' => 'pagination',
          ],
          'linkPagerWrapperTemplate' => '<div class="button-news-more"><div class="wrapper"><div class="paging">{pager}</div></div></div>',
          'eventOnPageChange' => 'function() {{{ias}}.hidePagination();}',
          'eventOnReady' => 'function() {{{ias}}.restorePagination();}',
     ],
]);

GridView

echo GridView::widget([
     'dataProvider' => $dataProvider,
     'pager' => [
        'class' => \kop\y2sp\ScrollPager::className(),
        'container' => '.grid-view tbody',
        'item' => 'tr',
        'paginationSelector' => '.grid-view .pagination',
        'triggerTemplate' => '<tr class="ias-trigger"><td colspan="100%" style="text-align: center"><a style="cursor: pointer">{text}</a></td></tr>',
     ],
]);

Configuration

General Options

Extensions

Extension Options

Plugin Events

Report

License

yii2-scroll-pager is released under the MIT License. See the bundled LICENSE.md for details.

Resources