You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for the awesome gem. It has been of great help on sorting/filtering my data inside my application.
I'm having difficulties when trying to sort the table with filterrific_sorting_link(@filterrific, :column_name). It works flawlessly when a search is made with a string, however, when I try sorting the records by a column after filtering between dates, the record table gets duplicated, with the second one being non-functional (as in, the sorting does not apply to the duplicated table).
The sorting works for the first table of records, but the view is messed up.
Question is, have you ever saw this behavior and do you know a fix?
Obs: Sorry for the bad formatting, this is my first Issue ever and I'm still learning how to make them.
scope :sorted_by, lambda { |sort_option|
direction = (sort_option =~ /desc$/) ? 'desc' : 'asc'
case sort_option.to_s
when /^date_/
order("losses.date #{ direction }")
when /^category_/
order("losses.category #{ direction }")
when /^source_/
order("losses.source #{ direction }")
when /^item_/
order("losses.item #{ direction }")
when /^loss_type_/
order("losses.loss_type #{ direction }")
when /^status_/
order("losses.status #{ direction }")
when /^price_/
order("losses.price #{ direction }")
when /^tax_/
order("losses.tax #{ direction }")
when /^total_ttc_/
order("losses.total_ttc #{ direction }")
when /^discount_/
order("losses.discount #{ direction }")
when /^total_/
order("losses.loss_total #{ direction }")
when /^invoice_number_/
order("losses.invoice_number #{ direction }")
else
raise(ArgumentError, "Invalid sort option: #{ sort_option.inspect }")
end
}
'# This scope was used for 'single' word search | Being kept here for reference
'# scope :search_query, lambda { |query|
'# return nil if query.blank?
'# terms = query.downcase.split(/\s+/)
'# terms = terms.map { |e|
'# (e.gsub('*', '%') + '%').gsub(/%+/, '%')
' # }
' # num_or_conds = 5
' # where(
'# terms.map { |term|
' # "(LOWER(losses.category) LIKE ? OR LOWER(losses.source) LIKE ? OR LOWER(losses.item) LIKE ? OR LOWER(losses.loss_type) LIKE ? OR LOWER(losses.status) LIKE ? )"
'# }.join(' AND '),
'# *terms.map { |e| [e] * num_or_conds }.flatten
' # )
'# }
def index
@filterrific = initialize_filterrific(
Loss,
params[:filterrific],
:persistence_id => false,
) or return @Losses = @filterrific.find.paginate(page: params[:page], per_page: 10).page(params[:page])
respond_to do |format|
format.html
format.js
end
# End of Index
end
Example image of the view on a browser after filtering by date range and trying to sort the table.
The text was updated successfully, but these errors were encountered:
crova
changed the title
silterrific_sorting_link() duplicates the result table when filtering by date_at_gte and date_at_lt
filterrific_sorting_link() duplicates the result table when filtering by date_at_gte and date_at_lt
Jan 21, 2018
First of all, thanks for the awesome gem. It has been of great help on sorting/filtering my data inside my application.
I'm having difficulties when trying to sort the table with filterrific_sorting_link(@filterrific, :column_name). It works flawlessly when a search is made with a string, however, when I try sorting the records by a column after filtering between dates, the record table gets duplicated, with the second one being non-functional (as in, the sorting does not apply to the duplicated table).
The sorting works for the first table of records, but the view is messed up.
Question is, have you ever saw this behavior and do you know a fix?
Obs: Sorry for the bad formatting, this is my first Issue ever and I'm still learning how to make them.
My loss model
class Loss < ApplicationRecord
include PgSearch
#scopes
filterrific(
default_filter_params: { sorted_by: 'date_desc' },
available_filters: [
:search_query,
:sorted_by,
:search_for,
:payed_at_gte,
:payed_at_lt
]
)
scope :sorted_by, lambda { |sort_option|
direction = (sort_option =~ /desc$/) ? 'desc' : 'asc'
case sort_option.to_s
when /^date_/
order("losses.date #{ direction }")
when /^category_/
order("losses.category #{ direction }")
when /^source_/
order("losses.source #{ direction }")
when /^item_/
order("losses.item #{ direction }")
when /^loss_type_/
order("losses.loss_type #{ direction }")
when /^status_/
order("losses.status #{ direction }")
when /^price_/
order("losses.price #{ direction }")
when /^tax_/
order("losses.tax #{ direction }")
when /^total_ttc_/
order("losses.total_ttc #{ direction }")
when /^discount_/
order("losses.discount #{ direction }")
when /^total_/
order("losses.loss_total #{ direction }")
when /^invoice_number_/
order("losses.invoice_number #{ direction }")
else
raise(ArgumentError, "Invalid sort option: #{ sort_option.inspect }")
end
}
'# This scope was used for 'single' word search | Being kept here for reference
'# scope :search_query, lambda { |query|
'# return nil if query.blank?
'# terms = query.downcase.split(/\s+/)
'# terms = terms.map { |e|
'# (e.gsub('*', '%') + '%').gsub(/%+/, '%')
' # }
' # num_or_conds = 5
' # where(
'# terms.map { |term|
' # "(LOWER(losses.category) LIKE ? OR LOWER(losses.source) LIKE ? OR LOWER(losses.item) LIKE ? OR LOWER(losses.loss_type) LIKE ? OR LOWER(losses.status) LIKE ? )"
'# }.join(' AND '),
'# *terms.map { |e| [e] * num_or_conds }.flatten
' # )
'# }
scope :search_query, lambda { |query|
search_by_keywords(query)
}
pg_search_scope :search_by_keywords,
against: %i[
category
source
item
loss_type
status
],
using: {
tsearch: { prefix: true },
# :ignoring => :accents
}
' # Enf od Ruby Class
end
My loss controller
def index
@filterrific = initialize_filterrific(
Loss,
params[:filterrific],
:persistence_id => false,
) or return
@Losses = @filterrific.find.paginate(page: params[:page], per_page: 10).page(params[:page])
respond_to do |format|
format.html
format.js
end
# End of Index
end
My index.html.erb view
<%= notice %>
Expenses
<%= render( partial: 'losses/list', locals: { losses: @Losses } )%>
My index.js.erb
<% js = escape_javascript(
render(partial: 'losses/list', locals: { losses: @Losses})
) %>
$("#filterrific_results").html("<%= js %>");
My _list.html.erb
<% end %>
<% @losses.each do |loss| %>
<% end %>Example image of the view on a browser after filtering by date range and trying to sort the table.
The text was updated successfully, but these errors were encountered: