Advanced Filtering

If your application needs something beyond the standard Streamlined filtering, you can infuse your app with a hearty dose of electrolytes and enable the shiny new advanced filtering. Simply add the following code to app/helpers/application_helper.rb, and voilà.

  def advanced_filtering
    true
  end

With that simple addition to application_helper.rb, you can

  • Filter on any database field appearing in the list, as well as filtering on association fields.
  • Add multiple filters, and Streamlined will AND them together.
  • Use the comparison operators right in the UI: <=, >=, <, >, =, is (“is null”, “is blank”, “is empty”, “is nil”), after, or before. (If no operand is specified the default query is a “LIKE”, just as in the standard Streamlined filters.)

Advanced Filtering Examples

  • Select “name” (or some other text field) and enter “john” to return all the names containing “john”
  • Select “name” and enter ”=john” (or “is john”) to return all the names exactly matching “john”
  • Select a numeric field and enter “100” to return all the numbers containing “100” (100, 1000, 5100, etc.)
  • Select a numeric field and enter ”=100” (or “is 100”) to return all the number equal to 100. (And of course you can use <, >, etc.)
  • Select a date field, and…
    • Enter ”> 2007-05-20” (or “after 2007-05-20”) to return all items after May 20th
    • Select that date field again and add another filter to get a range of dates
      • Enter ”< 2007-06-20” (or “before 2007-06-20”) for dates before June 20th, 2007
    • Enter “2007” for all items in 2007
    • Enter “2007-05” for all items in May, 2007

Filtering on association fields

If you define particular fields to show up for an association in the modelUI file then you will be able to filter on any of those that are real db fields.

Streamlined.ui_for(Article) do

      user_columns :title,

                   :authors,

                   {

                     :show_view => [:name, {:fields => [:first_name, :last_name, :full_name]}],

                     :edit_view => [:select, {:fields => [:first_name, :last_name, :full_name]}]

                   }

end

This will allow you to filter on Article:title as well as Author:first_name and Author:last_name. Author:full_name is not a real db field (in this case) so you would not be able to filter on it.

Upgrade Notes

If you have streamlined linked as an external, and you didn’t reinstall the plugin, you won’t get the new layout file and won’t see the filtering. Either run the rake task (rake streamlined:install_files) or copy over the streamlined layout file from plugins/streamlined/files/streamlined.rhtml to app/views/layouts.