PHPackages                             sanex/yii2-simple-filter - 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. sanex/yii2-simple-filter

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

sanex/yii2-simple-filter
========================

Simple Yii2 filter module with checkboxes

0.9.1(11y ago)1756213[4 issues](https://github.com/sanex3339/Yii2-Simple-Filter/issues)WTFPLPHP

Since Mar 9Pushed 10y ago4 watchersCompare

[ Source](https://github.com/sanex3339/Yii2-Simple-Filter)[ Packagist](https://packagist.org/packages/sanex/yii2-simple-filter)[ RSS](/packages/sanex-yii2-simple-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

Yii2-Simple-Filter
==================

[](#yii2-simple-filter)

Yii2 Simple Filter Module

Yii2 Simple Filter Module v0.9.1dev #####Not compatible with older versions, because methods names were changed!

Video:

\###Installation: How to install and configure modlue on clear Yii2 Base application (video): [http://www.youtube.com/watch?v=Wnn\_xVcTun0](http://www.youtube.com/watch?v=Wnn_xVcTun0)

Install module through [composer](http://getcomposer.org/download/)

Run

```
$ php composer.phar require --prefer-dist sanex/yii2-simple-filter "dev-master"

```

or add

```
"sanex/yii2-simple-filter": "dev-master"

```

to the `require` section of `composer.json` file.

Last step: add `'enablePrettyUrl' => true` to the `urlManager` in config file. ######Module not working with `'enablePrettyUrl' => false`!

\###How to use?

\####Controller: In controller, which has view (main view), where you want show data with filter, you must create object with instance of `SimplyFilter` module and set to him parameters:

```
use sanex\simplefilter\SimpleFilter;

...

$model = new Catalog;

$ajaxViewFile = '@sanex/catalog/views/catalog/catalog-ajax';

$filter = SimpleFilter::getInstance();
$filter->setParams([
    'model' => $model,
    'query' => $query,
    'useAjax' => true,
    'useCache' => true,
    'useDataProvider' => true,
]);

```

`$ajaxViewFile` - alias (or path) to ajax view, where you want to show data. You must create that view file before continue.

`setParams()` properties:

`model` - model, which data need to filter;

`query` - (optional) - \\yii\\db\\ActiveQuery object, see below;

`useAjax` - (optional, if not set - `true`) you can choose between Ajax or non-Ajax filtering by setting this parameter to boolean `true` or `false` values;

`useCache` - (optional, if not set - `false`) if (bool) true - return cached data, if (int) value - cache duration in seconds;

`useDataProvider` - (optional, if not set - `false`) if (bool) true - return data in Ajax View as dataProvider, if (bool) false or not set - return data as model;

As default, result query with filter looks like `SELECT COUNT(*) FROM 'catalog' WHERE 'color' IN ('Green', 'Red')`

If you want create custom query with filter you must set `query` parameter in `setParams()` method with `\yii\db\ActiveQuery` object as method parameter, that contain query parameters.

```
$query = new \yii\db\ActiveQuery($model);
$query->select(['id', 'name', 'size', 'price', 'country'])->where(['country' => 'Canada'])->orderBy(['price' => SORT_ASC]);

```

Method `limit()` of \\yii\\db\\ActiveQuery object can set parameter `'pagination' => ['pageSize' => $this->limit]`, of ActiveDatapProvider object.

```
$query = new \yii\db\ActiveQuery($model);
$query->limit(25);

```

If `limit()` method not set, then `limit` for each query will set to default value - 50 rows per page.

If you want to use custom pagination with this filter, you can get `offset` from GET-paremeter `page`. Need to know, what for `page` values `0` and `1`, `offset` value will `0`, for all other values - will calculated by formula `(page - 1) * limit`.

In main view, you must call `setFilter()` method contain array with filter parameters. ######Note! `property` must be same as names of table columns which you want to filter, and `values` must be same as this columns data.

\####Main View

```
$filter->setFilter([
    [
        'property' => 'color',
        'caption' => 'Color',
        'values' => [
            'Red',
            'Green',
            'Blue',
            'Black'
        ],
        'class' => 'horizontal'
    ],
    [
        'property' => 'size',
        'caption' => 'Size',
        'values' => [
            '45x45',
            '50x50',
            '60x60'
        ]
    ]
]);

```

You can set additional class or classes to each filters group by setting `class` property. This filter has two default style for checkbox: `horizontal` and `vertical` class for vertical checkboxes placement. If `class` property not set, used `horizontal` class as default. You can set `class` value as string: `'class' => 'horizontal additional class'`or as array: `'class' => ['vertical', 'additionalClass']`

Then, where you want to render ajax view with filtered data, call `renderAjaxView()` method:

```
$filter->renderAjaxView($ajaxViewFile, ['testParam' => $testParam]);

```

`$ajaxViewFile` - Ajax View file;

`(array)$ajaxViewParams` - (optional) parameters, that will be send to ajax view.

\####Ajax View In ajax view, you can get filtered data (model or dataProvider) through `$simpleFilterData` variable.

\######Note! Module pass to ajax view only data! You must create in that ajax view `` or use GridView widget to show data, same way as with all other Yii2 models!

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~10 days

Total

4

Last Release

4050d ago

### Community

Maintainers

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

---

Top Contributors

[![sanex3339](https://avatars.githubusercontent.com/u/9210534?v=4)](https://github.com/sanex3339 "sanex3339 (14 commits)")

---

Tags

filteryii2moduleyiicheckbox

### Embed Badge

![Health badge](/badges/sanex-yii2-simple-filter/health.svg)

```
[![Health](https://phpackages.com/badges/sanex-yii2-simple-filter/health.svg)](https://phpackages.com/packages/sanex-yii2-simple-filter)
```

###  Alternatives

[cyneek/yii2-routes

Routing and filtering extension system for Yii2 framework that emulates the Laravel routing system.

202.1k](/packages/cyneek-yii2-routes)[thrieu/yii2-grid-view-state

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

1313.1k1](/packages/thrieu-yii2-grid-view-state)

PHPackages © 2026

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