pcrt/yii2-ajax-pager
最新稳定版本:1.0.31
Composer 安装命令:
composer require pcrt/yii2-ajax-pager
包简介
Yii2-select2 widget implementation
README 文档
README
Yii2 Component extend yii\widgets\ContentDecorator url used to add ajax-pagination functionality to GridView and ListView base component .
This extension create a Wrapper around content and permit to chose between "Paginator Pattern" or "InfiniteScroll Pattern" to manage pagination functionality without reload page .
##Installation
The preferred way to install this extension is through composer.
Either run
$ php composer.phar require pcrt/yii2-ajax-pager "@dev"
or add
"pcrt/yii2-ajax-pager": "@dev"
to the require section of your composer.json file.
Usage
Once the extension is installed, you can add component in your View: The component can work as Pagination :
use pcrt/Paginator; .... <?php Paginator::begin([ 'type' => 'Pagination', 'id' => 'pcrt-pagination', // Id of pagination container 'id_wrapper' => 'pcrt-pagination-wrapper', // Id of wrapper container 'view' => $this, ]) ?> $this->renderPartial('ajax/list', [ 'dt' => $dataProvider ]); // or do your magic here ! <?php Paginator::end() ?>
or in InfiniteScroll mode:
use pcrt/Paginator; .... <?php Paginator::begin([ 'type' => 'InfiniteScroll', 'append' => '.pcrt-card', // Selector for pagination element extractor 'id_wrapper' => 'pcrt-pagination-wrapper', // Id of wrapper container 'view' => $this, ]) ?> $this->renderPartial('ajax/_card', [ 'dt' => $dataProvider ]); // or do your magic here ! <?php Paginator::end() ?>
You can also pass an alternative "wapper view" file :
use pcrt/Paginator; .... <?php Paginator::begin([ 'type' => 'InfiniteScroll', 'viewFile' => '@app/views/wrapper.php', // Alternative view Wrapper 'append' => '.pcrt-card', // Selector for pagination element extractor 'id_wrapper' => 'pcrt-pagination-wrapper', // Id of wrapper container 'view' => $this, ]) ?> // Remenber to return $content variable inside of wrapper;
In the controller for InfiniteScroll return a renderAjax file:
class MyController extends Controller { public function actionGetGridView(){ public function actionGetGridView($pageNumber=0,$pageSize=50){ if($pageSize == ""){ $pageSize = 50; } $request = \Yii::$app->request; $searchModel = new MyControllerSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->pagination = [ 'pageSize'=>$pageSize, 'page'=>$pageNumber-1, ]; $result = $dataProvider->getTotalCount(); $data = $this->renderAjax('_list', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); return $data; } } }
for Pagination return a jSON Object with data (html render) and total (total number of element):
class MyController extends Controller { public function actionGetGridView($pageNumber=0,$pageSize=50){ \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if($pageSize == ""){ $pageSize = 50; } $request = \Yii::$app->request; $searchModel = new MyControllerSearch(); $dataProvider = $searchModel->search(); $dataProvider->pagination = [ 'pageSize'=>$pageSize, 'page'=>$pageNumber-1, ]; $result = $dataProvider->getTotalCount(); $data = $this->renderAjax('_list', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); return ['html'=>$data,'total'=>$result]; } }
License
Yii2-Ajax-Pager is released under the BSD-3 License. See the bundled LICENSE.md for details.
Useful URLs
Enjoy!
统计信息
- 总下载量: 1.04k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-02-04