N
N
nerabio2017-10-03 15:39:17
Yii
nerabio, 2017-10-03 15:39:17

Dynamic filter in yii2 for gridView?

Good afternoon, tell me if I'm thinking in the right direction.
There is a classic grid and search models, all standard created by gii, the question is how to make a convenient filter where the filter field and value are added by the button, all in a compact form. Here is an example from Bitrix 1432848161198.jpg, you can add a condition.
So the plan is this:
1. An object with parameters will be created in JS:
obj = {
items: {
id: 1, field
: name,
value: text,
type: like
}....
}
description.
2. Then we pass JSON to the search model, convert it to an array and apply it in a foreach loop
$json = '{
"items": {
"id": 1,
"field": "name",
"value": "text",
"type": "like"
}
}';
$obj = json_decode($json, true);
foreach($obj as $key => $item){
$query->andFilterWhere([$item['type'], $item['field'], $item['value']]);
}
return $dataProvider;
So apply filters, are there ready made components for yii2?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Korobkov, 2017-10-03
@nerabio

https://github.com/unclead/yii2-multiple-input
but it's without grouping "and" / "or"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question