1. Go to this page and download the library: Download pcrt/yii2-ajax-pager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pcrt / yii2-ajax-pager example snippets
use pcrt/Paginator;
....
Paginator::begin([
'type' => 'Pagination',
'id' => 'pcrt-pagination', // Id of pagination container
'id_wrapper' => 'pcrt-pagination-wrapper', // Id of wrapper container
'view' => $this,
])
use pcrt/Paginator;
....
Paginator::begin([
'type' => 'InfiniteScroll',
'append' => '.pcrt-card', // Selector for pagination element extractor
'id_wrapper' => 'pcrt-pagination-wrapper', // Id of wrapper container
'view' => $this,
])
use pcrt/Paginator;
....
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,
])
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;
}
}
}