Introduction ¶
The Yii Advanced Filters extension improves Yii's grid view filters by allowing users to enter more powerful search terms. Multiple filter expressions can be combined together when filtering a single column, allowing for complex filters to be applied.
By default, the extension will understand the following patterns when they are entered into a grid filter:
Syntax | Description |
word1 word2 word3 | All words must appear in any order. |
"search term" | The value must match the search term exactly. |
#search term# | The value must contain the exact search term. |
/regex/ | The value must match the regular expression pattern. |
n1 to n2 | Numerically between n1 and n2 inclusive. |
< n1 <= n1 | Numerically less than [or equal to] n1. |
> n1 >= n1 | Numerically greater than [or equal to] n1. |
= n1 | Numerically equal to n1. |
! filter | Invert any filter listed above with an exclamation mark. |
filter1 | filter2 | The value must match at least one of the combined filters. |
filter1 & filter2 | The value must match all of the combined filters. |
For instance, the filters could be used and combined in the following ways:
Examples | |
< 400 & !"" | Numerically less than 400 and not blank. |
=100 | =200 | =300 | Numerically equal to either 100, 200 or 300. |
gold & ! fool's & ! pyrite | Contains the word gold, but not fool's or pyrite. |
/^[A-Z][0-9]+$/ | A letter followed by one or more numbers (MySQL). |
! /[A-Z]/ | Does not contain any letters (MySQL). |
1 to 100 & ! . & /[02468]$/ | Even integers between 1 and 100. |
Note that with most delimiters the whitespace is optional, so <400&!"" and < 400 & ! "" are equivalent.
Currently, MySQL and SQL Server databases are supported. See the guide section about extending database helpers if you need to add support for other databases.
Requirements ¶
The extension is targeted at Yii 1.1.x.
Yii2 soon?
Would be great to have this for Yii2 too...
Another nice addition would be with dates; >2014-06-30
or ranges 2014-01-01 to 2014-03-31
Re: Yii2 soon?
@mxd
I'll definitely release a version for Yii 2, but I've got no experience with it yet. I'd welcome advice from people more proficient in Yii 2 on how to port it.
Date ranges are a good idea and I'll probably implement them as a new filter class. Perhaps the filter could use PHP's strtotime to get the timestamp, allowing people to use more natural language for the dates. The user might then be able to enter something like "12th Jan to 15th Jan". The YYYY-MM-DD format would still work as a more structured input.
Date Range Suggestions
I've posted a reply on the forum topic with my current thoughts on date processing. If anyone would like to offer feedback while this is still in development, please do so in that topic.
View the topic.
UPDATE:
I've uploaded a preview of the date functionality.
Here's the relevant section of the guide.
Here's the updated demo.
Note that this just a preview and the functionality is subject to change.
Let me know your thoughts.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.