mazpaijo / yii2-querybuilder
Extension for Yii2 Framework to work with jQuery QueryBuilder
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 34
Type:yii2-extension
Requires
- bower-asset/bootstrap: 3.3.* | 3.2.* | 3.1.*
- bower-asset/jquery-querybuilder: 2.1.*
- yiisoft/yii2: 2.0.*
- yiisoft/yii2-bootstrap: 2.0.*
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is auto-updated.
Last update: 2024-12-12 17:39:14 UTC
README
This is the jQuery QueryBuilder extension for Yii 2. It encapsulates QueryBuilder component in terms of Yii widgets, and thus makes using QueryBuilder component in Yii applications extremely easy
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist leandrogehlen/yii2-querybuilder "*"
or add
"leandrogehlen/yii2-querybuilder": "*"
to the require section of your composer.json
file.
How to use
View:
use leandrogehlen\querybuilder\QueryBuilderForm; <?php QueryBuilderForm::begin([ 'rules' => $rules, 'builder' => [ 'id' => 'query-builder', 'filters' => [ ['id' => 'id', 'label' => 'Id', 'type' => 'integer'], ['id' => 'name', 'label' => 'Name', 'type' => 'string'], ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string'] ] ] ])?> <?= Html::submitButton('Apply'); ?> <?= Html::resetButton('Reset'); ?> <?php QueryBuilderForm::end() ?>
Controller:
use leandrogehlen\querybuilder\Translator; public function actionIndex() { $query = Customer::find(); $rules = Json::decode(Yii::$app->request->get('rules')); if ($rules) { $translator = new Translator($rules); $query ->andWhere($translator->where()) ->addParams($translator->params()); } $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); return $this->render('index', [ 'dataProvider' => $dataProvider, 'rules' => $rules ]); }