PHP code example of thrieu / yii2-grid-view-state

1. Go to this page and download the library: Download thrieu/yii2-grid-view-state 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/ */

    

thrieu / yii2-grid-view-state example snippets


namespace \app\widgets;

use thrieu\grid\FilterStateInterface;
use thrieu\grid\FilterStateTrait;

class GridView extends \yii\grid\GridView implements FilterStateInterface {
    use FilterStateTrait;
}

use \app\widgets\Gridview;
...

GridView::widget([
...
    'as filterBehavior' => \thrieu\grid\FilterStateBehavior::className(),
...
]);

// DataProvider
$dataProvider = new ActiveDataProvider([
    'query' => $query,
    'pagination' => [
        'params' => \app\widgets\GridView::getMergedFilterStateParams(),
    ],
    'sort' => [
        'params' => \app\widgets\GridView::getMergedFilterStateParams(),
    ],
]);
// Filter model
$this->load(\app\widgets\GridView::getMergedFilterStateParams());


    public function behaviors()
    {
        return [
            ...
            'clearFilterState' => \thrieu\grid\ClearFilterStateBehavior::className(),
            ...
        ];
    }


        $form = Html::beginForm();
        $form .= Html::hiddenInput('clear-state', '1');
        $form .= Html::hiddenInput('redirect-to', '');
        $form .= Button::widget([
            'label' => Yii::t('app', 'Reset filter'),
        ]);
        $form .= Html::endForm();
        echo $form;

$filterData = GridView::getMergedFilterStateParams(null, null, 'delivery/cmd-delivery/index');
$model->load($filterData);


use \app\widgets\Gridview;
...

GridView::widget([
...
    'as filterBehavior' => \thrieu\grid\FilterStateBehavior::class,
    'usePrevNext' => true,
...
]);

        $prevNext = new PrevNextPage('cars/in-way/index');

        if ($prevId = $prevNext->getPrevPage($model->id)) {
            echo ThButton::widget([
                    'tooltip' => Yii::t('blankonthema', 'Previous record'),
                    'link' => [
                        'view',
                        'id' => $prevId,
                    ],
                    'icon' => 'arrow-left',
                    'type' => ThButton::TYPE_DEFAULT
                ]);
        }
        if ($nextId = $prevNext->getNextPage($this->id)) {
            echo ThButton::widget([
                'tooltip' => Yii::t('blankonthema', 'Next record'),
                'link' => [
                    'view',
                    'id' => $nextId,
                ],
                'icon' => 'arrow-right',
                'type' => ThButton::TYPE_DEFAULT
            ]);
        }