Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filtering by multiple selected values #3027

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/assets/javascripts/rails_admin/ra.filter-box.js
Expand Up @@ -99,6 +99,10 @@
$('<a href="#" class="switch-select"></a>')
.append($('<i></i>').addClass('icon-' + (multiple_values ? 'minus' : 'plus')))
);
additional_control =
$('<input class="additional-fieldset default input-sm form-control" type="hidden" />')
.prop('value', field_operator)
.prop('name', operator_name);
break;
case 'string':
case 'text':
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/rails_admin/main_helper.rb
Expand Up @@ -67,6 +67,7 @@ def ordered_filter_string
end
case field.type
when :enum
options[:operator] = field.search_operator
options[:select_options] = options_for_select(field.with(object: @abstract_model.model.new).enum, filter_hash['v'])
when :date, :datetime, :time
options[:datetimepicker_format] = field.parser.to_momentjs
Expand All @@ -76,7 +77,7 @@ def ordered_filter_string
options[:type] = field.type
options[:value] = filter_hash['v']
options[:label] = field.label
options[:operator] = filter_hash['o']
options[:operator] = filter_hash['o'] if filter_hash['o'].present?
%{$.filters.append(#{options.to_json});}
end.join("\n").html_safe if ordered_filters
end
Expand Down
2 changes: 2 additions & 0 deletions lib/rails_admin/abstract_model.rb
Expand Up @@ -159,6 +159,8 @@ def build_statement_for_integer_decimal_or_float
case @operator
when 'between'
range_filter(range_begin, range_end)
when 'in'
["(#{@column} IN (?))", Array.wrap(@value)]
else
column_for_value(val) if val
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rails_admin/config.rb
Expand Up @@ -198,7 +198,7 @@ def current_user_method(&block)
end

def default_search_operator=(operator)
if %w(default like starts_with ends_with is =).include? operator
if %w(default like starts_with ends_with is in =).include? operator
@default_search_operator = operator
else
raise(ArgumentError.new("Search operator '#{operator}' not supported"))
Expand Down