ajax - Create a like method for filter query on Rails, smart_listing gem -
i want filter content of table created smart_listing gem
for unknown, smartlisting known smart_listing
ruby gem provides tools create lists on rails app
i can use pagination filter still not working
link smart_listing documentation controls (filtering) documentation section
in docs says that:
# apply search control filter. # note: `like` method here not built-in rails scope. need define yourself. users_scope = users_scope.like(params[:filter]) if params[:filter]
this code, how can make runs filter? have on controller
if !current_user.current_organization.import_columns.nil? @import_contacts = userimport.where(organization_id: current_user.current_organization.id) @import_contacts_column_filter = current_user.current_organization.import_columns.split(/,/) contacts_import_scope = @import_contacts contacts_import_scope = contacts_import_scope.like(params[:filter]) if params[:filter] #contacts_import_scope = begin_of_association_chain.order('active desc') #contacts_import_scope = contacts_import_scope.imported_users_filter(params[:filter].strip) if params[:filter] @import_contacts_listing = smart_listing_create( :import_contacts, contacts_import_scope, partial: 'contacts/listing_import', default_sort: {created_at: "desc"} ) end
this on views
index.html.slim
.tab-content - if @import_contacts.any? .search-wrapper.pull-right = smart_listing_controls_for(:import_contacts) span.btn.pull-right i.fa.fa-search .filter.input-append.pull-right = text_field_tag :filter, '', class: 'search', placeholder: "#{t('commons.filters.search_pending_petition_contacts')}", autocomplete: 'off'
_listing_import.slim
- unless smart_listing.empty? .pending_contacts_table.table-responsive table class="table-striped table-list" style="width: 100%; background-color: #fafbfd;" thead tr - @import_contacts_column_filter.each |column| th.name.col-sm-2 = smart_listing.sortable "#{column}", "#{column}" th.name.col-sm-2 añadir tbody - smart_listing.collection.each |user_imported| tr - @import_contacts_column_filter.each |field| td = "#{user_imported.send(field)}" td - if user.exists?(email: user_imported.email) p ya añadido - else - last_name = "#{user_imported.surname1}"+"#{user_imported.surname2}" = link_to new_organization_customer_path(name: user_imported.name, last_name: last_name, email: user_imported.email, tmp_pass: user_imported.tmp_pass), class: 'btn btn-success' class='fa fa-plus-square' = page_entries_info smart_listing.collection = smart_listing.paginate - else
how define doc's .like
method?
as wrote on code , left commented, before tried write in way without results.
#contacts_import_scope = contacts_import_scope.imported_users_filter(params[:filter].strip) if params[:filter]
solved!
issue importscontroller
, must defined on , not on contactscontroller
.
also controller looks this
def load_import_contacts @import_contacts_column_filter = current_user.current_organization.import_columns.split(/,/) @import_contacts = userimport.where(organization_id: current_user.current_organization.id) @import_contacts = @import_contacts.where("name ? or surname1 ? or surname2 ? or reference_number ? or email ? or mutua ?", "%#{params[:filter]}%","%#{params[:filter]}%", "%#{params[:filter]}%", "%#{params[:filter]}%","%#{params[:filter]}%", "%#{params[:filter]}%") if params[:filter] @import_contacts_listing = smart_listing_create( :import_contacts, @import_contacts,
and _listing_import.slim
...
@import_contacts = @import_contacts.where("name ? or surname1 ? or surname2 ? or reference_number ? or email ? or mutua ?", "%#{params[:filter]}%","%#{params[:filter]}%", "%#{params[:filter]}%", "%#{params[:filter]}%","%#{params[:filter]}%", "%#{params[:filter]}%") if params[:filter]
finally, filter , pagination works!
Comments
Post a Comment