-
Notifications
You must be signed in to change notification settings - Fork 329
API: FieldSearch
The FieldSearch action is an advanced search. It provides a UI to allow specification of a value and operator for each searchable field. Text fields can be searched using operators such as “Begins With”, “Ends With”, “Contains”, “=”, “>=”, etc.
Set this property so link is included in a group of links.
The set of searchable columns. This list defaults to the textual database fields.
config.field_search.columns = :user_type, :widget_id, :name, :owner, :status
For virtual columns you must also set the “search_sql” option or the field will not appear on the search form.
config.columns[:admin_roles].search_sql = 'users.role_id'
The value of “search_sql” will also be available in the Search Overrides condition_for_x method in case you need to customize the search SQL.
Set the default params for some fields.
Active scaffold supports html, js, json, yaml, and xml formats by default. If you need to add another mime type for field search, you can do it here. The format is then added to the default formats.
Examples:
config.field_search.formats << :pdf
# or
config.field_search.formats = [:pdf]
A flag for whether the search should do full-text searching in the database (LIKE ?) or assume that search tokens will match the beginning (LIKE ?%). Default is :true.
Since v2.3 is replaced with text_search
An array of column names so user can pick one column to group by it and get aggregated list. The values can be symbols of column names, which will display the column’s translated name, or an array of label and column name. Instead of column name, a `#` string can be used, to group by column using SQL function. See Grouped Searches for a further explanation.
An array of column names to replace `config.list.columns` when using a grouped search. If not defined, it will default to include all columns from `config.list.columns` which have calculation defined. The group column is always added at the beginning.
Enable it to display a message with humanized search conditions instead of default filtered message.
The action link used to tie the Search box to the List table. See API: Action Link for the options on this setting.
Put some rarely-used columns in a hidden group.
When enabled, reset link will clear input fields in the search form, instead of refreshing the list without search and closing the form.
A flag for how the search should do full-text searching in the database:
- :full (LIKE %?%)
- :start (LIKE ?%)
- :end (LIKE %?)
- false (LIKE ?)
Default is :full
.
When a drop down (select) is used, the “false” option will use LIKE with no wild cards, which is fast!
config.field_search.text_search = false
API: Column related methods
To customize the search form columns, use search_ui (similar to form_ui). Note that we can’t use a :checkbox search_ui because it’s not possible to determine whether or not to search for that field (:checkbox will silently render a :boolean search_ui, which is displayed as a select)
Examples:
Field Search Example (with dropdown for user type)
class UsersController < ActionController::Base
active_scaffold :users do |config|
config.actions = [:nested, :list, :show, :field_search]
config.columns[:user_type].search_ui = :select
end
end
module UsersHelper
# display the "user_type" field as a dropdown with options
def user_type_search_column(record, input_name)
select :search, :user_type, options_for_select(User.user_types), {:include_blank => as_(:_select_)}, input_name
end
end