@@ -10,7 +10,7 @@ Docs in progress! Please review the examples.
1010
1111## Examples
1212
13- ### Example 1: Table rendering with custom row actions
13+ ### Table rendering with custom row actions
1414
1515``` ruby
1616def response
@@ -72,7 +72,7 @@ def customer_delete_action_config customer
7272end
7373```
7474
75- ### Example 2: Table rendering with joined model and formatted col data rendering
75+ ### Table rendering with joined model and formatted col data rendering
7676
7777``` ruby
7878def response
@@ -119,7 +119,101 @@ def table_item_actions order
119119end
120120```
121121
122- ### Example 3: Custom collection rendering
122+ ### Table rendering formatted col data rendering access the whole row instance object
123+
124+ ``` ruby
125+ def response
126+ # ...
127+ bs_smart_collection collection_config
128+ # ...
129+ end
130+
131+ def collection_config
132+ {
133+ id: ' orders' ,
134+ items: Order .all,
135+ paginate: 10 ,
136+ rerender_on: " success" ,
137+ columns: {
138+ self: {
139+ heading: ' Price in €' ,
140+ format: -> (order){ " #{ order.price_in_euro } €" },
141+ }
142+ }
143+ }
144+ end
145+ ```
146+
147+ ### Table rendering formatted col data rendering access the whole row instance object in multiple columns
148+
149+ ``` ruby
150+ def response
151+ # ...
152+ bs_smart_collection collection_config
153+ # ...
154+ end
155+
156+ def collection_config
157+ {
158+ id: ' orders' ,
159+ items: Order .all,
160+ paginate: 10 ,
161+ rerender_on: " success" ,
162+ # the columns hash can only have a key once, fix by specifying the attribute name
163+ columns: {
164+ price_in_euro: {
165+ heading: ' Price in €' ,
166+ format: -> (column_data){ " #{ column_data } €" },
167+ },
168+ price_in_euro_again: {
169+ attribute: :price_in_euro , # fix by specifying the attribute name
170+ heading: ' Price in €' ,
171+ format: -> (column_data){ " #{ column_data } €" },
172+ },
173+ self: {
174+ heading: ' Price in €' ,
175+ format: -> (order){ " #{ order.price_in_euro } €" },
176+ },
177+ self_again: {
178+ attribute: :self , # fix by specifying the attribute name
179+ heading: ' Price in €' ,
180+ format: -> (order){ " #{ order.price_in_euro } €" },
181+ }
182+ }
183+ }
184+ end
185+ ```
186+
187+ ### Table rendering via slot enabling flexible column content composition
188+
189+ ``` ruby
190+ def response
191+ # ...
192+ bs_smart_collection collection_config
193+ # ...
194+ end
195+
196+ def collection_config
197+ {
198+ id: ' orders' ,
199+ items: Order .all,
200+ paginate: 10 ,
201+ rerender_on: " success" ,
202+ columns: {
203+ price_in_euro: {
204+ heading: ' Price in € accessed via row object' ,
205+ slot: method(:price_in_euro_column_slot ) # slots ALWAYS get the whole row object passed in!
206+ }
207+ }
208+ }
209+ end
210+
211+ def price_in_euro_column_slot order
212+ bs_badge order.price_in_euro # or whatever you want to do with all kinds of components
213+ end
214+ ```
215+
216+ ### Custom collection rendering
123217
124218``` ruby
125219def response
@@ -183,4 +277,3 @@ def product_delete_action_config product
183277 }
184278end
185279```
186-
0 commit comments