Answer the question
In order to leave comments, you need to log in
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 , 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
https://github.com/unclead/yii2-multiple-input
but it's without grouping "and" / "or"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question