Skip to content

Instantly share code, notes, and snippets.

@michalkorzawski
Created August 15, 2022 14:19
Show Gist options
  • Save michalkorzawski/99ff03cb07897d84f8b12ea8a0643d62 to your computer and use it in GitHub Desktop.
Save michalkorzawski/99ff03cb07897d84f8b12ea8a0643d62 to your computer and use it in GitHub Desktop.
def results
params_hash = element.dataset['params-hash'].present? ? JSON.parse(element.dataset['params-hash']) : filtered_params
query = (element.dataset.from_search_input ? element.value : element.value.presence) || params_hash['query']
params_hash['query'] = query
pagy, collection = pagy(active_record_collection(filters), page: page)
cable_ready.morph(
children_only: true,
selector: '#id_of_a_dom_element',
html: render(
PaginationComponent.new(
pagy: pagy,
params_hash: params_hash.to_json,
collection: collection
), layout: false
)).morph(
selector: '#query',
html: "<input type='hidden' name='query' id='query' value='#{query}'>"
).set_dataset_property(
selector: '#search-query-field-id',
name: 'paramsHash',
value: params_hahs.to_json
)
morph :nothing
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment