GithubHelp home page GithubHelp logo

leandrogehlen / yii2-querybuilder Goto Github PK

View Code? Open in Web Editor NEW
42.0 11.0 34.0 58 KB

Extension for Yii2 Framework to work with jQuery QueryBuilder

PHP 100.00%
yii2 yii2-widgets jquery-querybuilder

yii2-querybuilder's Introduction

jQuery QueryBuilder Extension for Yii 2

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

Yii2 Latest Stable Version Scrutinizer Code Quality Code Coverage Build Status Code Climate Total Downloads

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

The extension depends the bootstrap css then is necessary adds it in AppAsset:

class AppAsset extends AssetBundle {

    ...

    public $depends = [
        ...
        'yii\bootstrap\BootstrapAsset', // or 'yii\bootstrap4\BootstrapAsset'
    ];

}

View:

use leandrogehlen\querybuilder\QueryBuilderForm;

<?php QueryBuilderForm::begin([
    'rules' => $rules,
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            '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
    ]);
}

yii2-querybuilder's People

Contributors

leandrogehlen avatar sohelahmed7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-querybuilder's Issues

use of Plugins

Hi,
is there a way to use the plugins, i.e. slider, selectize and datepicker. Just tried and don't get it how to use them.

would be very nice, i need this components for my actual project.

with kind regards

peter

Custom Input

How do I implement the custom input in the filter? Do I pass in a php function or a string jquery function?

composer error

Hi

i am getting an error while doing composer update
The "https://bower.herokuapp.com/packages/search/jquery-querybuilder" file could not be downloaded (HTTP/1.1 404 Not Found)

If i remove yii2-querybuilder from composer.json - all the rest of dependencies work fine.
yii2-querybuilder is added in composer.json as "leandrogehlen/yii2-querybuilder": "*"

tried on also on a second (live) machine that should work fine otherwise and got the same result.

any ideas?

Replace Object with BaseObject

Since in PHP7 'Object' becase a reserved keyword.
Need to update all classes inherited from yii\base\Object, to make them inherited from yii\base\BaseObject

Feature request: multiple queries merged

Hi,

I'd like to propose an additional feature.

I have a situation where I need to add multiple query-builder objects into one query.
But what happens now is that the params in the Query are shared. I have code like that:

$query = new Query;
foreach ($my->usedFilters as $qhf) {
    $rules = Json::decode($qhf->questionFilter->filter);
    $translator = new Translator($rules);
    $query
            ->andWhere($translator->where())
            ->addParams($translator->params());
}

What happens here is that the params in Query is for the whole query. With each loop the params will be reassigned as p0, p1 .. pn and with each loop they get overwritten.

So I am thinking that the Translator could have something like setCurrentParams($params) where you could set the already assigned params and the next ones would be added on top rather than overwritten.

so we would have code like that for my implementation

$query = new Query;
foreach ($my->usedFilters as $qhf) {
    $rules = Json::decode($qhf->questionFilter->filter);
    $translator = new Translator($rules);
    $translator->setCurrentParams($query->params);
    $query
            ->andWhere($translator->where())
            ->addParams($translator->params());
}

Cannot install the package

$ composer require leandrogehlen/yii2-querybuilder "*"

[UnexpectedValueException]
Could not parse version constraint >=~2: Invalid version string "~2"

Question: is there a reason that rules isn't passed directly by pluginOptions?

Hi i have seen your extension for the JQueryBuilder and have one Question.

Is there a reason that you pass the $rules to the QueryBuilderForm and not add it to the pluginOptions directly?

<?php QueryBuilderForm::begin([
    'rules' => $rules,
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            'filters' => [
                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
            ]
        ]
    ]
])?>

Which would then add JS code to set the rules.

instead of set it directly?

<?php QueryBuilderForm::begin([
    'builder' => [
        'id' => 'query-builder',
        'pluginOptions' => [
            'rules' => $rules,
            'filters' => [
                ['id' => 'id', 'label' => 'Id', 'type' => 'integer'],
                ['id' => 'name', 'label' => 'Name', 'type' => 'string'],
                ['id' => 'lastName', 'label' => 'Last Name', 'type' => 'string']
            ]
        ]
    ]
])?>

I mean you even didn't use the $rules given to the QueryBuilderForm e.g. add the json version already to the echo Html::hiddenInput($this->rulesParam); as value?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.