PHPackages                             thrieu/yii2-grid-view-state - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. thrieu/yii2-grid-view-state

ActiveYii2-extension[Search &amp; Filtering](/categories/search)

thrieu/yii2-grid-view-state
===========================

Save filters from GridView to session, keep the filter state between pages.

v1.0(8y ago)1313.1k↓33.3%9[2 issues](https://github.com/thrieu/yii2-grid-view-state/issues)1BSD 3-ClausePHP

Since Oct 19Pushed 6y ago5 watchersCompare

[ Source](https://github.com/thrieu/yii2-grid-view-state)[ Packagist](https://packagist.org/packages/thrieu/yii2-grid-view-state)[ Docs](https://github.com/thrieu/yii2-grid-view-state)[ RSS](/packages/thrieu-yii2-grid-view-state/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (1)

yii2-grid-view-state
====================

[](#yii2-grid-view-state)

Save filters from GridView to session, keep filter state between pages.

Features
--------

[](#features)

1. Very flexible. Separate setting and getting.
2. Setting via behavior.
3. Determines uniqueness by action's route and a customizable ID.

Installation
------------

[](#installation)

To install, either run

```
php composer.phar require --prefer-dist thrieu/yii2-grid-view-state "dev-master"

```

or add

```
"thrieu/yii2-grid-view-state": "dev-master"

```

to the require section of your `composer.json` file and then run `composer update`.

Usage
-----

[](#usage)

### Step 1

[](#step-1)

Create \\app\\widgets\\Gridview.php

Extend `GridView` class, simply implement `FilterStateInterface` and `FilterStateTrait`.

```
namespace \app\widgets;

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

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

### Step 2

[](#step-2)

Attach the filter behavior to your `GridView` widget.

```
use \app\widgets\Gridview;
...

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

### Step 3

[](#step-3)

Update \\app\\models\\xxxSearch.php

To get the params which is merged with GridView state params and GET query params, and then set it to filter model and `DataProvider`.

```
// 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());
```

Enjoy it.

### Clear state

[](#clear-state)

Update \\app\\controllers\\xxxController.php

Add `ClearFilterStateBehavior` to `behaviors()` of your controller.

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

And then add a form to your frontend page.

```
        $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;
```

### get filter settings by route

[](#get-filter-settings-by-route)

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

### Prev Next model for view screens

[](#prev-next-model-for-view-screens)

for gridview set usepreview = true

```
use \app\widgets\Gridview;
...

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

for prev next buttons easy get previousa nd next model keys values

```
        $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
            ]);
        }
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b5d8b071bb4501fde7d51699b73fdc0742086f05b16248b7a6c7626c44e50b56?d=identicon)[thrieu](/maintainers/thrieu)

---

Top Contributors

[![tranch](https://avatars.githubusercontent.com/u/5999732?v=4)](https://github.com/tranch "tranch (5 commits)")[![Azwartin](https://avatars.githubusercontent.com/u/7689921?v=4)](https://github.com/Azwartin "Azwartin (1 commits)")[![gatis-ozols](https://avatars.githubusercontent.com/u/30055755?v=4)](https://github.com/gatis-ozols "gatis-ozols (1 commits)")[![uldisn](https://avatars.githubusercontent.com/u/3525344?v=4)](https://github.com/uldisn "uldisn (1 commits)")

---

Tags

gridviewyii2filteryii2extensionwidgetgridview

### Embed Badge

![Health badge](/badges/thrieu-yii2-grid-view-state/health.svg)

```
[![Health](https://phpackages.com/badges/thrieu-yii2-grid-view-state/health.svg)](https://phpackages.com/packages/thrieu-yii2-grid-view-state)
```

###  Alternatives

[richardfan1126/yii2-sortable-gridview

Sortable GridView for Yii2

29189.3k](/packages/richardfan1126-yii2-sortable-gridview)[keygenqt/yii2-autocomplete-ajax

A simple way to search model id of the attributes model

1015.8k](/packages/keygenqt-yii2-autocomplete-ajax)[sjaakp/yii2-alphapager

Page data on initial character in Yii2.

184.4k](/packages/sjaakp-yii2-alphapager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
