Yii Advanced Filters

This is the discussion topic for the Yii Advanced Filters extension.

The extension allows users to enter more powerful expressions into grid view filters, for example:

word1 word2 word3

  • All words must appear in any order.

< 400 & !""

  • Numerically less than 400 and not blank.

! /[A-Z]/

  • Does not include any letters.

Project page and more examples • Try a demo • Extension page • Github repository

I’ve put a lot of effort into the documentation, so I hope it’ll be easy to install and use. It should also be easy to customise.

Any feedback on the extension and documentation will be appreciated. I’ll accept any issues through the GitHub issue tracker. I will also consider pull requests.

Date Comparison - Suggestions Welcome

I’m working on the date comparison functions at the moment, but I’d like to get some feedback before proceeding.

By default, the filter will use strtotime() to turn the user entered date into a timestamp, so more natural expressions can be entered. A different function can be provided in config.


I’m considering the following patterns:

date - The exact date

date1 to date2 - Between date1 and date2 inclusive

< date - Before the specified date

<= date - On or before the specified date

>= date - On or after the specified date

> date - After the specified date


So, for example, you could enter the following filters:

today - Date is today’s

>= yesterday - Date is yesterday’s or later

> 4th Jan - Date is after 4th Jan this year.

today to today + 7 days - Between today and seven days after today.

Or to prevent any ambiguity:

< 2015-01-25 - before 25th Jan 2015.


Problems

  • Very English-centric - PHP’s strtotime can only process English date expressions. The implementer can, however, change the function that is used.

  • Natural syntax may cause confusion - if people can enter "today" and other natural language expressions, they might think they can enter "Jan 2014" or "in Jan 2014" or "during Jan 2014" to find any records in January. The first will actually be processed as January 1st and the other two will not be treated as dates at all.


I’d welcome any suggestions. I don’t want to make the system too confusing.

I’ve uploaded a preview of the date functionality.

Here’s the relevant section of the guide.

Here’s the updated demo.

In short, it recognises date expressions using PHP’s strtotime() function by default and can compare ranges using the same syntax as for numeric ranges. By default, expressions such as the following are supported:

  • = today

Date is today.

  • > 4th Jan

Date is after 4th Jan this year.

  • 2015-01-05 to yesterday

Date is between 5th Jan 2015 and yesterday.

I’m not entirely happy with the syntax, so I’d be happy to receive any feedback. The functionality of the preview is subject to change, so I’ve not pushed any changes to GitHub yet.

Hi,any news for yii2 ?

Thanks