@@ -23,7 +23,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
2323 end
2424
2525 def response
26- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
26+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
2727 collection_content @collection .config do
2828 @collection .paginated_data.each do |product |
2929 paragraph text: product.name
@@ -59,7 +59,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
5959 end
6060
6161 def response
62- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
62+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
6363 collection_content @collection .config do
6464 @collection .paginated_data.each do |product |
6565 paragraph text: product.name
@@ -72,8 +72,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
7272 def pagination
7373 plain " showing #{ @my_collection .from} "
7474 plain " to #{ @my_collection .to} "
75- plain " of #{ @my_collection .filtered_count} "
76- plain " from total #{ @my_collection .base_count} "
75+ plain " of #{ @my_collection .base_count} "
7776 collection_content_previous do
7877 button text: " previous"
7978 end
@@ -119,7 +118,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
119118
120119 def response
121120 filter
122- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
121+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
123122 collection_content @collection .config do
124123 @collection .paginated_data.each do |product |
125124 paragraph text: product.name
@@ -141,7 +140,22 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
141140 end
142141 end
143142
144- # ...
143+ def pagination
144+ plain " showing #{ @my_collection .from} "
145+ plain " to #{ @my_collection .to} "
146+ plain " of #{ @my_collection .base_count} "
147+ collection_content_previous do
148+ button text: " previous"
149+ end
150+ @my_collection .pages.each do |page |
151+ collection_content_page_link page: page do
152+ button text: page
153+ end
154+ end
155+ collection_content_next do
156+ button text: " next"
157+ end
158+ end
145159
146160end
147161```
@@ -151,4 +165,56 @@ That's it. Now we can filter our collection by product name.
151165
152166### Ordering
153167
154- ![ Coming Soon] ( ../../images/coming_soon.png )
168+ Ordering a collection can be achieved by using the ` collection_order_toggle ` helper along with ` get_collection_order ` to receive the selected order.
169+
170+ ``` ruby
171+ class Shop ::Pages ::Products ::Index < Matestack ::Ui ::Page
172+ include Matestack ::Ui ::Core ::Collection ::Helper
173+
174+ def prepare
175+ @collection_id = ' products-collection'
176+ base_query = Products .all
177+
178+ order = get_collection_order(@collection_id )
179+ ordered_query = Products .all.order(current_order)
180+
181+ @collection = set_collection(
182+ id: @collection_id ,
183+ data: ordered_query,
184+ init_limit: 20 ,
185+ base_count: base_query.count
186+ )
187+ end
188+
189+ def response
190+ order
191+ async id: ' product-collection' , rerender_on: " #{ @collection_id } -udpate" do
192+ collection_content @collection .config do
193+ @collection .paginated_data.each do |product |
194+ paragraph text: product.name
195+ end
196+ end
197+ end
198+ pagination
199+ end
200+
201+ def order
202+ collection_order @my_collection .config do
203+ plain " sort by:"
204+ collection_order_toggle key: :title do
205+ button do
206+ plain " Title"
207+ collection_order_toggle_indicator key: :title , asc: ' ↑' , desc: ' ↓'
208+ end
209+ end
210+ end
211+ end
212+
213+ # ...
214+
215+ end
216+ ```
217+
218+ ## Complete documentation
219+
220+ If you want to know all details about the collection component as well as more example on how to use filtering, ordering and pagination together checkout its [ api documentation] ( /docs/api/100-components/collection.md ) .
0 commit comments