@@ -23,7 +23,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
23
23
end
24
24
25
25
def response
26
- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
26
+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
27
27
collection_content @collection .config do
28
28
@collection .paginated_data.each do |product |
29
29
paragraph text: product.name
@@ -59,7 +59,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
59
59
end
60
60
61
61
def response
62
- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
62
+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
63
63
collection_content @collection .config do
64
64
@collection .paginated_data.each do |product |
65
65
paragraph text: product.name
@@ -72,8 +72,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
72
72
def pagination
73
73
plain " showing #{ @my_collection .from} "
74
74
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} "
77
76
collection_content_previous do
78
77
button text: " previous"
79
78
end
@@ -119,7 +118,7 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
119
118
120
119
def response
121
120
filter
122
- async id: ' product-collection' , rerender_on: ' product-collection- udpate' do
121
+ async id: ' product-collection' , rerender_on: " #{ @collection_id } - udpate" do
123
122
collection_content @collection .config do
124
123
@collection .paginated_data.each do |product |
125
124
paragraph text: product.name
@@ -141,7 +140,22 @@ class Shop::Pages::Products::Index < Matestack::Ui::Page
141
140
end
142
141
end
143
142
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
145
159
146
160
end
147
161
```
@@ -151,4 +165,56 @@ That's it. Now we can filter our collection by product name.
151
165
152
166
### Ordering
153
167
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