tonisormisson/yii1-querybuilder

jQuery Query-builder widget for Yii1

Installs: 10

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

Type:yii-extension

0.1.7 2017-07-19 09:47 UTC

This package is auto-updated.

Last update: 2024-03-27 21:16:45 UTC


README

This is an implementation of jQuery Querybuilder for Yii1

DEMO

https://demo.andmemasin.eu/yii1-querybuilder/

Dependencies

this widget depends on jQuery and Bootstrap3. Due to Yii1 widgets logic the widget itself does not manage the dependencies. You need to install & load the jQuery and Bootstrap3 in your app yourself prior using this widget!

Basic usage example

In view:

echo CHtml::beginForm();
$this->widget('ext.yii1-querybuilder.QueryBuilder',
    [
        'model'=>$model,
        'attribute'=>'myquerystring',
        'filters'=>[
            ['id'=>'name','label'=>'Name (string)','type'=>'string'],
            ['id'=>'age','label'=>'Age (integer)','type'=>'integer'],
            ['id'=>'height','label'=>'Height (double)','type'=>'double'],
            ['id'=>'birthday','label'=>'Birthday (date)','type'=>'date'],
            ['id'=>'time','label'=>'Time (time)','type'=>'time'],
            ['id'=>'changed_at','label'=>'Last changed (datetime)','type'=>'datetime'],
            ['id'=>'is_active','label'=>'Is Active? (boolean)','type'=>'boolean'],
        ],
        'rules'=>$rules,

    ]);

echo CHtml::submitButton('go');
echo CHtml::endForm();

In Controller:

public function actionIndex()
{
    $model = new SomeModel();
        if(isset($_POST['SomeModel'])){
            $model->attributes =$_POST['SomeModel'];
            $rules = json_decode($someModel->myquerystring);
            if($rules){
                Yii::import('application.extensions.yii1-querybuilder.Translator');
                // translate rules to SQL (with params)
                $translator = new Translator($rules);
                // feed the translated sql & params to Yii find() method
                $result = SomeModel::model()->find($translator->where, $translator->params);
            }
        }
        $this->render('index',[
            'rules'=>$rules,
        ]);
}