Module: Datagrid::Filters::ClassMethods
- Defined in:
- lib/datagrid/filters.rb
Overview
self.included
Instance Method Summary collapse
- #default_filter ⇒ Object
-
#filter(name, type = :default, options = {}, &block) ⇒ Object
Defines new datagrid filter.
-
#filter_by_name(attribute) ⇒ Object
Returns filter definition object by name.
- #filters ⇒ Object
- #inspect ⇒ Object
Instance Method Details
#default_filter ⇒ Object
113 114 115 |
# File 'lib/datagrid/filters.rb', line 113 def default_filter DefaultFilterScope.new end |
#filter(name, type = :default, options = {}, &block) ⇒ Object
Defines new datagrid filter. This method automatically generates attr_accessor
for filter name and adds it to the list of datagrid attributes.
Arguments:
-
name
- filter name -
type
- filter type that defines type case and GUI representation of a filter -
options
- hash of options -
block
- proc to apply the filter
Available options:
-
:header
- determines the header of the filter -
:default
- the default filter value. Able to accept aProc
in case default should be recalculated -
:range
- if true, filter can accept two values that are treated as a range that will be used for filtering Not all of the filter types support this option. Here are the list of types that do::integer
,:float
,:date
,:datetime
,:string
-
:multiple
- if true multiple values can be assigned to this filter. If String is assigned as a filter value, it is parsed from string using a separator symbol (‘,` by default). But you can specify a different separator as option value. Default: false. -
:allow_nil
- determines if the value can be nil -
:allow_blank
- determines if the value can be blank -
:before
- determines the position of this filter, by adding it before the filter passed here (when using datagrid_form_for helper) -
:after
- determines the position of this filter, by adding it after the filter passed here (when using datagrid_form_for helper) -
:dummy
- if true, this filter will not be applied automatically and will be just displayed in form. In case you may want to apply it manually. -
:if
- specify the condition when the filter can be dislayed and used. Accepts a block or a symbol with an instance method name -
:unless
- specify the reverse condition when the filter can be dislayed and used. Accepts a block or a symbol with an instance method name
See: github.com/bogdan/datagrid/wiki/Filters for examples
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/datagrid/filters.rb', line 95 def filter(name, type = :default, = {}, &block) if type.is_a?(Hash) = type type = :default end klass = type.is_a?(Class) ? type : FILTER_TYPES[type] raise ConfigurationError, "filter class #{type.inspect} not found" unless klass position = Datagrid::Utils.(filters_array, ) filter = klass.new(self, name, , &block) filters_array.insert(position, filter) datagrid_attribute(name) do |value| filter.parse_values(value) end end |
#filter_by_name(attribute) ⇒ Object
Returns filter definition object by name
53 54 55 56 57 58 |
# File 'lib/datagrid/filters.rb', line 53 def filter_by_name(attribute) return attribute if attribute.is_a?(Datagrid::Filters::BaseFilter) self.filters.find do |filter| filter.name == attribute.to_sym end end |
#filters ⇒ Object
121 122 123 |
# File 'lib/datagrid/filters.rb', line 121 def filters filters_array end |
#inspect ⇒ Object
117 118 119 |
# File 'lib/datagrid/filters.rb', line 117 def inspect "#{super}(#{filters_inspection})" end |