Collection
Prerequisites
Examples
Filterable collection
class Pages::MyApp::Collection < Matestack::Ui::Page
include Matestack::Ui::Core::Collection::Helper
def prepare
my_collection_id = "my-first-collection"
current_filter = get_collection_filter(my_collection_id)
my_base_query = DummyModel.all
my_filtered_query = my_base_query
.where("title LIKE ?", "%#{current_filter[:title]}%")
@my_collection = set_collection({
id: my_collection_id,
data: my_filtered_query
})
end
def response
heading size: 2, text: "My Collection"
filter
# the content has to be wrapped in an `async` component
# the event has to be "your_custom_collection_id" + "-update"
async rerender_on: "my-first-collection-update", id: "my-collection-content" do
content
end
end
def filter
collection_filter @my_collection.config do
collection_filter_input key: :title, type: :text, placeholder: "Filter by Title"
collection_filter_submit do
button text: "filter"
end
collection_filter_reset do
button text: "reset"
end
end
end
def content
collection_content @my_collection.config do
ul do
@my_collection.data.each do |dummy|
li do
plain dummy.title
end
end
end
end
end
endFiltered & paginated collection
Filtered & paginated & ordered collection
Action enriched collection
Last updated
Was this helpful?