Hello. There is yii2, there is a table column "price". Tell me how to organize a search by price range, for example: search from 100 to 200? Maybe there is a module, or is there an article on the implementation of this? I searched, but found nothing sensible. I will be glad to any information about this.
- Good day! And what will happen in this case is a filter - an input field or a drop-down list with prepared options? - Lesha Marchenkovsky
- oneKind. input field - firebear
- Are you going to enter two numbers separated by a space or how? - Lesha Marchenkovsky
- two fields: "from" and "to") - firebear
- As an example, GridView - nix-tips.ru/… . There is an example with filtering by name. You need to do the same, passing the values from and to, writing WHERE myField> = from AND myField <= to - Daniel Protopopov
|
1 answer
You can use the kartik-v / yii2-grid extension , which allows you to use various types of columns and various filters on the GridView, including the one you need.
Repository link: https://github.com/kartik-v/yii2-grid
approximate configuration for your table with a column "Price" and a filter on it:
GridView::widget([ 'columns' => [ [ 'attribute' => 'price', //в качестве фильтра будет использован виджет kartik\range\RangeInput 'filterType' => GridView::FILTER_RANGE ] ] ]) Unfortunately, I cannot say for sure on the server side, but most likely there will need to catch a specific field (or two) and insert them in between in the SQL query. Although, it is possible that the extension will do it for you!
|