Codxplore.com

Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now https://play.google.com/store/apps/details?id=com.akramhossin.bukharisharif

Yii2 GridView sorting and pagination using pajax


Yii2 GridView sorting and pagination using pajax

In this article we will learn how to use Pjax for Yii2 grid view sorting and pagination.

Pjax is a jquery plugin which progressively enhances website page loads and behave more like single-page web application.

We need to these steps to enable Pjax in yii2 web page

  • Import yii\widgets\Pjax class
  • Begin Pjax widget using Pjax::begin()
  • Code block which needs to be rendered using Pjax
  • Close Pjax widget  Pjax::end()

Below code is the example of how to use pjax for yii2 grid view sorting and pagination

use yii\widgets\Pjax

Add above line in the beginning of your view. 

Pjax::begin();
GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yiigridSerialColumn'],
        'id',
        'branch:ntext',
        'version:ntext',
        'release_date:ntext',
        [
            'class' => 'yiigridActionColumn',
            'template' => '{view}',
        ],
    ],
]);
Pjax::end()

Tags : PHP, Yii2,

Views : 1833

Subscribe Us


Follow Us