wice_grid_mongoid 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG +409 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1172 -0
  5. data/Rakefile +42 -0
  6. data/SAVED_QUERIES_HOWTO.rdoc +123 -0
  7. data/VERSION +1 -0
  8. data/generators/common_templates/icons/arrow_down.gif +0 -0
  9. data/generators/common_templates/icons/arrow_up.gif +0 -0
  10. data/generators/common_templates/icons/calendar_view_month.png +0 -0
  11. data/generators/common_templates/icons/delete.png +0 -0
  12. data/generators/common_templates/icons/expand.png +0 -0
  13. data/generators/common_templates/icons/page_white_excel.png +0 -0
  14. data/generators/common_templates/icons/page_white_find.png +0 -0
  15. data/generators/common_templates/icons/table.png +0 -0
  16. data/generators/common_templates/icons/table_refresh.png +0 -0
  17. data/generators/common_templates/icons/tick_all.png +0 -0
  18. data/generators/common_templates/icons/untick_all.png +0 -0
  19. data/generators/common_templates/initializers/wice_grid_config.rb +215 -0
  20. data/generators/common_templates/locales/wice_grid.yml +269 -0
  21. data/generators/common_templates/stylesheets/wice_grid.css +173 -0
  22. data/generators/wice_grid_assets_jquery/templates/USAGE +6 -0
  23. data/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js +161 -0
  24. data/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb +35 -0
  25. data/generators/wice_grid_assets_prototype/USAGE +8 -0
  26. data/generators/wice_grid_assets_prototype/templates/javascripts/calendarview.js +1168 -0
  27. data/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js +153 -0
  28. data/generators/wice_grid_assets_prototype/templates/stylesheets/calendarview.css +107 -0
  29. data/generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb +37 -0
  30. data/init.rb +1 -0
  31. data/install.rb +1 -0
  32. data/lib/grid_output_buffer.rb +52 -0
  33. data/lib/grid_renderer.rb +531 -0
  34. data/lib/helpers/js_calendar_helpers.rb +188 -0
  35. data/lib/helpers/wice_grid_misc_view_helpers.rb +113 -0
  36. data/lib/helpers/wice_grid_serialized_queries_view_helpers.rb +82 -0
  37. data/lib/helpers/wice_grid_view_helpers.rb +781 -0
  38. data/lib/js_adaptors/jquery_adaptor.rb +145 -0
  39. data/lib/js_adaptors/js_adaptor.rb +12 -0
  40. data/lib/js_adaptors/prototype_adaptor.rb +168 -0
  41. data/lib/table_column_matrix.rb +51 -0
  42. data/lib/view_columns.rb +469 -0
  43. data/lib/views/create.rjs +13 -0
  44. data/lib/views/delete.rjs +12 -0
  45. data/lib/wice_grid.rb +809 -0
  46. data/lib/wice_grid_controller.rb +165 -0
  47. data/lib/wice_grid_core_ext.rb +179 -0
  48. data/lib/wice_grid_misc.rb +99 -0
  49. data/lib/wice_grid_serialized_queries_controller.rb +77 -0
  50. data/lib/wice_grid_serialized_query.rb +14 -0
  51. data/lib/wice_grid_spreadsheet.rb +33 -0
  52. data/tasks/wice_grid_tasks.rake +28 -0
  53. data/test/.gitignore +2 -0
  54. data/test/database.yml +21 -0
  55. data/test/schema.rb +33 -0
  56. data/test/test_helper.rb +89 -0
  57. data/test/views/projects_and_people_grid.html.erb +12 -0
  58. data/test/views/projects_and_people_grid_invalid.html.erb +12 -0
  59. data/test/views/simple_projects_grid.html.erb +9 -0
  60. data/test/wice_grid_core_ext_test.rb +183 -0
  61. data/test/wice_grid_functional_test.rb +68 -0
  62. data/test/wice_grid_misc_test.rb +41 -0
  63. data/test/wice_grid_test.rb +42 -0
  64. data/test/wice_grid_view_helper_test.rb +12 -0
  65. data/uninstall.rb +1 -0
  66. data/wice_grid_mongoid.gemspec +111 -0
  67. metadata +141 -0
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ GPATH
3
+ GRTAGS
4
+ GSYMS
5
+ GTAGS
6
+ cand
7
+ doc/
8
+ log/
data/CHANGELOG ADDED
@@ -0,0 +1,409 @@
1
+ wice_grid_custom_filter_params used to be a view helper, not it is also accessible from the controller, to be used in cases like redirect_to(my_resource_path(wice_grid_custom_filter_params(...)))
2
+
3
+ auto reloading filters
4
+
5
+ helper export_to_csv_javascript to create custom CSV buttons
6
+ option :hide_csv_button to hide the default CSV export button
7
+
8
+ Method WiceGrid#selected_records and parameter :after were a bit of a mess and have been substituted by
9
+
10
+ * WiceGrid#current_page_records returning records on the current page
11
+ * WiceGrid#all_pages_records returning records browsable throughout all pages
12
+ * :with_paginated_resultset - callback to process records on the current page
13
+ * :with_resultset - callback to process records browsable throughout all pages
14
+
15
+ Compliant with Rails 1.2.8 with or without rails_xss and erubis
16
+
17
+ Ruby 1.9.1 compliance
18
+
19
+ Dropdowns generated with :custom_filter => :auto and :custom_filter => [method chain] are now ordered by option labels
20
+
21
+ how_filters => false is the same as :show_filters => :no and :show_filters => true is the same as :show_filters => :always
22
+
23
+ action_column - Adds a column with checkboxes for each record.
24
+ Useful for actions with multiple records, for example, delete
25
+ the selected records.
26
+
27
+ using merge_conditions to merge conditions :)
28
+
29
+ WiceGrid is now compatible with the new Rails XSS behavior which
30
+ will be the default in Rails 3.0 and can be used in Rails 2.3.5
31
+ using the rails_xss plugin.
32
+ Read http://github.com/nzkoz/rails_xss for more
33
+
34
+ wice_grid_custom_filter_params
35
+
36
+ support for with_scope and with_exclusive_scope
37
+
38
+ :total_entries parameter added to initialize_grid (will_paginate)
39
+
40
+ Localization
41
+
42
+ assert_keys wherever possible
43
+
44
+ == 0.5
45
+
46
+ Today "WiceGrid":http://leikind.org/pages/wicegrid has reached its next level of maturity and was awarded the tag of version 0.5.
47
+
48
+ This version of WiceGrid is accompanied by an application called _WiceGrid Examples_ running "online":http://grid.leikind.org/ and with source code available on "GitHub":http://github.com/leikind/wice_grid_examples.
49
+
50
+ Here's a list of changes as compared with "version 0.4":https://blog.wice.eu/2009/7/6/moving-to-github-and-wicegrid-version-0-4 :
51
+
52
+ h4. selected_records
53
+
54
+ Method @selected_records@ of WiceGrid instances allows to access the list of all records of the current selection throughout all pages in the context of a view:
55
+
56
+ --- RHTML
57
+ <%= grid(@tasks_grid) do |g|
58
+ ...
59
+ end -%>
60
+
61
+ <% selected = @tasks_grid.selected_records %>
62
+ <p><%= selected.size %> records selected: <%= selected.map(&:id).to_sentence %></p>
63
+ ---
64
+
65
+ "See an online example":http://grid.leikind.org/integration_with_application_view
66
+
67
+ h4. placement of filter related icons
68
+
69
+ A change in placement of filter related icons (filter icon, reset icon, show/hide icon): if the last column doesn't have any filter or a column name, icons will be placed in the header of this column, otherwise it falls back to the usual behavior when an additional table column is added. To change the behavior back to the old style, set @Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS@ to @false@ in the configuration file.
70
+
71
+ "See an online example":http://grid.leikind.org/custom_filters2
72
+
73
+
74
+ h4. wice_grid_assets generator
75
+
76
+ Copying asset files (images, css, js, and the configuration file) is now done by a plugin generator, not rake tasks:
77
+
78
+ ---
79
+ ./script/generate wice_grid_assets
80
+ ---
81
+
82
+ h4. blank slate
83
+
84
+ Blank slate feature: it is now possible to replace the grid with some alternative view if no filters are active and there are no records to render:
85
+
86
+ --- RHTML
87
+ <%= grid(@grid) do |g|
88
+
89
+ g.blank_slate do
90
+ "There are no records"
91
+ end
92
+
93
+ g.column do |product|
94
+ ...
95
+ end
96
+ end -%>
97
+ ---
98
+
99
+ There are also two alternative three ways to do it:
100
+
101
+ --- Ruby
102
+ g.blank_slate "some text to be rendered"
103
+ ---
104
+ and
105
+ --- Ruby
106
+ g.blank_slate :partial => "partial_name"
107
+ ---
108
+
109
+ "See an online example":http://grid.leikind.org/no_records
110
+
111
+ h4. custom filters with symbols
112
+
113
+ Improvement to custom filters, namely to
114
+ --- Ruby
115
+ :custom_filter => :symbol
116
+ ---
117
+ and
118
+ --- Ruby
119
+ :custom_filter => [:symbol1, :symbol2, :symbol3]
120
+ ---
121
+
122
+ Now, if the last method returns an array of 2 elements, the first element becomes the select option label and the second - the select option value (usually @id@).
123
+
124
+ Before this change the value returned by the method had been used for both the value and the label of the select option.
125
+
126
+ "See an online example":http://grid.leikind.org/custom_filters3
127
+
128
+ h4. custom filters and NULL
129
+
130
+ Values @null@ and @not null@ in a generated custom filter dropdown are treated specially, as SQL @null@ statement and not as strings. Value @null@ is transformed into SQL condition @IS NULL@, and @not null@ into @IS NOT NULL@ .
131
+
132
+ Thus, if in a filter defined by
133
+
134
+ --- Ruby
135
+ :custom_filter => {'No' => 'null', 'Yes' => 'not null', '1' => 1, '2' => '2', '3' => '3'}
136
+ ---
137
+ values @1@, @2@ and @'No'@ are selected (in a multi-select mode), this will result in the following SQL:
138
+
139
+ --- SQL
140
+ ( table.field IN ( '1', '2' ) OR table.field IS NULL )
141
+ ---
142
+
143
+ "See an online example":http://grid.leikind.org/null_values
144
+
145
+ h4. Wice::Defaults::STRING_MATCHING_OPERATORS
146
+
147
+ in addition to the configuration constant @Wice::Defaults::STRING_MATCHING_OPERATOR@ to define the operator for matching strings (@LIKE@ in most cases), hash @Wice::Defaults::STRING_MATCHING_OPERATORS@ was added to specify string matching operators on per-database basis:
148
+
149
+ --- Ruby
150
+ Wice::Defaults::STRING_MATCHING_OPERATORS = {
151
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
152
+ 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
153
+ }
154
+ ---
155
+
156
+ A use-case for this is a Rails application connecting to two databases, one of which is MySQL, and the other is Postgresql. To use case-insensitive matching in Postgresql 'ILIKE' has to be used, but this operator is unknown to MySQL.
157
+
158
+ h4. td_html_attrs and table_html_attrs shortcuts
159
+
160
+ @:td_html_attrs@ in column definitions and @table_html_attrs@ in the table definitions are mostly used to add css classes, so a shorter way has been added to add css classes.
161
+
162
+ Instead of
163
+
164
+ --- RHTML
165
+ <%= grid(@grid, :table_html_attrs => {:class => 'css_class1'}) do |g|
166
+ g.column(:td_html_attrs => {:class => 'css_class2'}) do
167
+ ...
168
+ end
169
+ end -%>
170
+ ---
171
+
172
+ It's possible to just use the new @:class@ option:
173
+
174
+ --- RHTML
175
+ <%= grid(@grid, :class => 'css_class1') do |g|
176
+ g.column(:class => 'css_class2') do
177
+ end
178
+ end -%>
179
+ ---
180
+
181
+ h4. allow_multiple_selection
182
+
183
+ New options for @column@: @:allow_multiple_selection@, use @:allow_multiple_selection => false@ to disable switching between single and multiple selection modes for custom dropdown boxes.
184
+
185
+ "See an online example":http://grid.leikind.org/custom_filters4
186
+
187
+ h4. allow_ordering
188
+
189
+ New parameter for @column@: @:allow_ordering@. Use @:allow_ordering => false@ to disable the ordering of the column.
190
+
191
+ "See an online example":http://grid.leikind.org/basics6
192
+
193
+ h4. allow_showing_all_records
194
+
195
+ Parameter @:allow_showing_all_records@ moved from @initialize_grid@ to the view helper.
196
+
197
+ h4. other
198
+
199
+ * Default styles updated.
200
+ * Javascript code cleaned up and refactored.
201
+ * Quite some number of bugs fixed
202
+
203
+ == 0.4
204
+
205
+ * Detached filters: it has become possible to detach filters and place them anywhere on the page, before or after the grid.
206
+ Read section "Detached Filters" in the README.
207
+
208
+ * More control over Submit and Reset buttons.
209
+ Two new view helpers: submit_grid_javascript returns javascript which applies current filters; reset_grid_javascript returns javascript
210
+ which resets the grid, clearing the state of filters. This allows to create your own Submit and Reset buttons anywhere on the page
211
+ with the help of button_to_function:
212
+
213
+ <%= button_to_function "Submit", submit_grid_javascript(@grid) %>
214
+ <%= button_to_function "Reset", reset_grid_javascript(@grid) %>
215
+
216
+ To complement this feature there are two new parameters in the +grid+ helper :hide_submit_button and :hide_reset_button which
217
+ hide default buttons in the grid if set to true. Together with detached filter this allows to completely
218
+ get rid of the filter row with filters and icons.
219
+
220
+ * erb_mode option has been moved to the grid view helper - watch for warnings and remove the parameter from initialize_grid if you have it there.
221
+
222
+ * helper include_wice_grid_assets will require WiceGrid javascripts and stylesheets on demand, that is, only if at least one initialize_grid
223
+ has been called in the controller. Otherwise the helper returns an empty string. However, you can force the old unconditioned behavior if you
224
+ need by submitting parameter :load_on_demand set to false:
225
+ <%= include_wice_grid_assets(:load_on_demand => false) %>
226
+
227
+ * Compatibility with Rails asset caching. Helpers names_of_wice_grid_stylesheets and names_of_wice_grid_javascripts return names of stylesheet and
228
+ javascript files and can be used with stylesheet_link_tag and javascript_include_tag with :cache => true. Using this trick you have to deal with
229
+ the parameters correctly, mind that Prototype has to be loaded before WiceGrid javascripts:
230
+
231
+ <%= stylesheet_link_tag *(['core', 'modalbox'] + names_of_wice_grid_stylesheets + [ {:cache => true}]) %>
232
+ <%= javascript_include_tag *([:defaults] + names_of_wice_grid_javascripts + [ 'ui', 'swfobject', {:cache => true}]) %>
233
+
234
+ * When a page with a WiceGrid instance is loaded there is check a small chunk of javascript that checks whether Prototype is loaded and whether
235
+ the main WiceGrid javascript files is loaded and is of the correct version. Problems are reported to the user via alert() dialog boxes.
236
+ This check has now been disabled in the production mode.
237
+
238
+ * The default field separator in generated CSV (comma) can now be overridden by setting :enable_export_to_csv to a string instead of +true+.
239
+
240
+ * It is possible to add your own handcrafted HTML after and/or before each grid row. This works similar to +row_attributes+,
241
+ by adding blocks after_row and before_row:
242
+
243
+ <%= grid(@tasks_grid) do |g|
244
+ g.before_row do |task|
245
+ if task.active?
246
+ "<tr><td colspan=\"10\">Custom line for #{t.name}</td></tr>" # this would add a row
247
+ # before every active task row
248
+ else
249
+ nil
250
+ end
251
+ end
252
+ .......
253
+ end %>
254
+
255
+
256
+
257
+ * Bug fixes
258
+
259
+ * Refactoring
260
+ =============
261
+
262
+ === 03/04/2009
263
+
264
+ Possibility to add custom lines after and/or before a grid row.
265
+
266
+
267
+ === 16/03/2009
268
+
269
+ Option to override the default field separator in generated CSV (comma).
270
+
271
+
272
+ === 13/02/2009
273
+
274
+ a bug fix for incorrect generation if dom ids for javascript calendar filter. Happened only for columns belonging to joined tables
275
+
276
+ === 12/01/2009
277
+
278
+ WiceGrid 0.3 released
279
+
280
+ === 12/01/2009
281
+
282
+ All records mode
283
+
284
+ === 10/12/2008
285
+
286
+ custom_filter made Rails-compliant, a new flavor - Array of two-element arrays
287
+
288
+ === 4/12/2008
289
+ A single helper to include all assets in a page
290
+
291
+ A javascript error message if Prototype is not loaded
292
+
293
+ A javascript error message if wice_grid.js is not loaded
294
+
295
+ Added status info to the pagination line:
296
+ « Previous 1 2 3 Next » 1-20 / 50
297
+
298
+ === 3/12/2008
299
+ First implementation of saved queries
300
+
301
+
302
+ === 25/11/2008
303
+
304
+ Negation for string filters: match records where this fiels DOES NOT include the given fragment.
305
+
306
+ === 24/11/2008
307
+
308
+ The string matching operator for string filters (LIKE) has been moved to wice_grid_config.rb in order to make it easier to substitute it with
309
+ something else, for example, ILIKE of Postgresql.
310
+
311
+
312
+ === 19/11/2008
313
+
314
+ Experimental feature : :table_alias parameter to allow ordering and filtering for joining associations referring the same table.
315
+ (See "Joined associations referring to the same table" in README)
316
+
317
+ === 18/11/2008
318
+
319
+ Refactoring
320
+
321
+ === 6/11/2008
322
+
323
+ Ability to provide a callback to a Proc object or a method, the callback will be called with the objects of the current selection of
324
+ objects (throughout all pages). Can be used to use the WiceGrid filters set up by the user for further processing of the user's selection of
325
+ objects.
326
+
327
+ === 5/11/2008
328
+
329
+ Javascript calendars as Date/Datetime filters
330
+
331
+
332
+ === 4/11/2008
333
+
334
+ Ability to inject custom sql code into the ORDER BY clause, for example, ORDER BY char_length(table1.foo)
335
+
336
+ === 4/11/2008
337
+
338
+ Creates a new branch for version 2.3
339
+
340
+
341
+
342
+ === 21/10/2008
343
+
344
+ A bugfix related to custom filters influencing other columns with filters
345
+ A more informative error message if the grid can't find the underlying database column for a view column (incorrect :column_name and :model_class)
346
+
347
+ === 8/10/2008
348
+
349
+ New view helper parameter <tt>:sorting_dependant_row_cycling</tt> - When set to true (by default it is false) the row styles +odd+ and +even+
350
+ will be changed only when the content of the cell belonging to the sorted column changes. In other words, rows with identical values in the
351
+ ordered column will have the same style (color).
352
+
353
+ === 3/10/2008
354
+
355
+ For simple columns like
356
+
357
+ g.column :column_name => 'Username', :attribute_name => 'username' do |account|
358
+ account.username
359
+ end
360
+
361
+ the following blockless shortcut can be used:
362
+
363
+ g.column :column_name => 'Username', :attribute_name => 'username'
364
+
365
+ In this case +attribute_name+ will be used as the method name to send to the ActiveRecord instance.
366
+
367
+ === revision 27 (30/09/2008)
368
+
369
+ * CSV export
370
+ * Custom filters can switch between a dropdown list and a multiple select list, thus allowing to search for records matching
371
+ more that one value (operator OR)
372
+
373
+ === revision 17 (19/08/2008)
374
+
375
+ * A bug fixed: extra_request_parameters did not propagate to will_paginate page panel. Now it does.
376
+
377
+ === revision 13 (6/08/2008)
378
+
379
+ * File <tt>config.rb</tt> renamed.
380
+ * New parameters for +column+ :
381
+ * <tt>:boolean_filter_true_label</tt> - overrides the default value for <tt>BOOLEAN_FILTER_TRUE_LABEL</tt> ('+yes+') in the config.
382
+ Only has effect in a column with a boolean filter.
383
+ * <tt>:boolean_filter_false_label</tt> - overrides the default value for <tt>BOOLEAN_FILTER_FALSE_LABEL</tt> ('+no+') in the config.
384
+ Only has effect in a column with a boolean filter.
385
+ * <tt>:filter_all_label</tt> - overrides the default value for <tt>BOOLEAN_FILTER_FALSE_LABEL</tt> ('<tt>--</tt>') in the config.
386
+ Has effect in a column with a boolean filter _or_ a custom filter.
387
+
388
+ === revision 11
389
+
390
+ * New row_attributes method to dynamically generate HTML attributes for the <tt><tr></tt> tag:
391
+
392
+ <%= grid(@portal_applications_grid) do |g|
393
+ g.row_attributes{ |portal_application|
394
+ {:id => "#{@portal_applications_grid.name}_row_#{portal_application.id}"}
395
+ }
396
+
397
+ g.column{ |portal_application| ... }
398
+ g.column{ |portal_application| ... }
399
+ end -%>
400
+
401
+ * The column block can now optionally return an array of two values, where the first element is the cell
402
+ contents and the second is a hash of HTML attributes to be added for the <td> tag of the current cell.
403
+
404
+ === revision 10
405
+
406
+ * New parameter +grid+ parameter: <tt>:extra_request_parameters</tt>.
407
+ (Read http://redmine.wice.eu/api/wice_grid/classes/Wice/GridViewHelper.html#M000002)
408
+
409
+ === 0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Yuri Leikind & the WICE team (http://wice.eu)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,1172 @@
1
+ = WiceGrid
2
+
3
+ Version:: 0.5.6
4
+ Author:: Yuri Leikind
5
+ Contributor:: Xavier Defrang
6
+ Homepage:: http://leikind.org/pages/wicegrid
7
+ Examples online:: http://grid.leikind.org
8
+ News:: http://leikind.org/wicegrid
9
+ Email:: "Yuri Leikind" <yuri.leikind at gmail dot com>
10
+
11
+ == Intro
12
+
13
+ WiceGrid is a Rails grid plugin.
14
+
15
+ One of the goals of this plugin was to allow the programmer to define the contents of the cell by himself, just like one does when rendering a collection via a simple table (and this is what differentiates WiceGrid from various scaffolding solutions), but automate implementation of filters, ordering, paginations, CSV export, and so on. Ruby blocks provide an elegant means for this.
16
+
17
+
18
+ WiceGrid builds the call to the ActiveRecord layer for you and creates a table view with the results of the call including:
19
+
20
+ * paging
21
+ * sortable columns
22
+ * filtering by multiple columns
23
+ * CSV export
24
+ * saving queries
25
+
26
+ All working nicely together. Filters are added automatically according to the type of the underlying DB column. Filtering by more than one column at the same time is possible. More than one such grid can appear on a page, and manipulations with one grid do not have any impact on the other.
27
+
28
+ WiceGrid does not take a collection as an input, it works directly with ActiveRecord (with the help of <tt>will_paginate[http://github.com/mislav/will_paginate/wikis]</tt>).
29
+
30
+ WiceGrid does not use AJAX calls to reload itself, instead simple GET requests are used for this, nevertheless, all other page parameters are respected and preserved. WiceGrid views do not contain forms so you can include it in your own forms.
31
+
32
+ WiceGrid is known to work with Rails versions from 2.1.x to 2.3.9. WiceGrid with Rails versions older
33
+ than 2.1 can still be functional depending on the functionalities used.
34
+
35
+ WiceGrid is known to work with MySQL and Postgres.
36
+
37
+ WiceGrid works with Prototype and jQuery (experimental).
38
+
39
+ WiceGrid is compliant with Ruby 1.9.1.
40
+
41
+ === Examples
42
+
43
+ This tutorial is accompanied by a sample application with WiceGrid examples which you can browse online ( http://grid.leikind.org ), or just view the code ( http://github.com/leikind/wice_grid_examples ).
44
+
45
+
46
+ == Requirements
47
+
48
+ Rails version 2.1.0 or newer.
49
+
50
+ <tt>will_paginate[http://github.com/mislav/will_paginate/wikis]</tt> version 2.3.15 or newer.
51
+
52
+ <tt>Prototype[http://www.prototypejs.org]</tt> version 1.5.1 or newer, or <tt>jQuery[http://jquery.com/]</tt>.
53
+
54
+ == How-To
55
+
56
+ === Installation
57
+
58
+ Run the following command to install the plugin:
59
+
60
+ script/plugin install git://github.com/leikind/wice_grid.git
61
+
62
+ If your application is Prototype-based (default in Rails 2.x), run the following generator to copy all plugin assets:
63
+
64
+ ./script/generate wice_grid_assets_prototype
65
+
66
+ For jQuery:
67
+
68
+ ./script/generate wice_grid_assets_jquery
69
+
70
+ This will copy images, stylesheets, configuration file <tt>config/initializers/wice_grid_config.rb</tt>, and the correct version
71
+ of javascript files.
72
+
73
+ === Support for Prototype and jQuery
74
+
75
+ WiceGrid started as a plugin using the Prototype javascript framework. Support for jQuery was added for version 0.6.
76
+ The plugin contains two versions of the main javascript file <tt>wice_grid.js</tt>, and depending on the generator run to
77
+ install the assets (+wice_grid_assets_prototype+ or +wice_grid_assets_jquery+) the correct file is copied into <tt>public/javascripts</tt>.
78
+
79
+ Some javascript code is also generated and injected into the HTML page. The value of constant <tt>Wice::Defaults::JS_FRAMEWORK</tt> in
80
+ configuration file <tt>wice_grid_config.rb</tt> defines for which JS framework code should be generated.
81
+ Generators +wice_grid_assets_prototype+ and +wice_grid_assets_jquery+ create a version of <tt>wice_grid_config.rb</tt>
82
+ with the corresponding value of <tt>Wice::Defaults::JS_FRAMEWORK</tt>.
83
+
84
+
85
+ In the Prototype mode the plugin uses a forked[http://github.com/leikind/calendarview] version of Calendarview[http://github.com/jsmecham/calendarview]. It is bundled with the plugin and the generator task
86
+ +wice_grid_assets_prototype+ will install al necessary assets.
87
+
88
+ The jQuery version uses jQuery datepicker[http://jqueryui.com/demos/datepicker/]. Because this is part
89
+ of the standard jQuery codebase, it is not bundled together with the plugin, and it is the responsibility
90
+ of the programmer to include all necessary assets including localization files if the application is
91
+ multilingual.
92
+
93
+ It is always possible to fall back to simple dropdown lists that the standard date/datetime Rails helpers use.
94
+
95
+ JQUERY DATEPICKER IS ONLY USED FOR DATE FILTERS AT THE MOMENT. DATETIME FILTERS FALL BACK TO THE DEFAULT
96
+ RAILS DATE/DATETIME HELPERS.
97
+
98
+
99
+ === Basics
100
+
101
+ The Prototype version of WiceGrid requires <tt>prototype.js</tt> and <tt>effects.js</tt> in order to function.
102
+ The jQuery version of WiceGrid requires <tt>jquery.js</tt> and <tt>jquery-ui.js</tt> in order to function.
103
+
104
+ Thus, make sure you have <tt><%=javascript_include_tag :defaults %></tt> in your layout template.
105
+
106
+ To include WiceGrid javascript and stylesheet files to the page use helper +include_wice_grid_assets+ :
107
+
108
+ <%= include_wice_grid_assets %>
109
+
110
+ The default behavior of +include_wice_grid_assets+ is a bit magical in the sense that it
111
+ produces no output if the page contains no grids, so don't panic if you see no WiceGrid includes.
112
+ If you prefer to always have WiceGrid stylesheet and javascript, use
113
+
114
+ <%= include_wice_grid_assets :load_on_demand => false %>
115
+
116
+ The simplest example of a WiceGrid for one simple DB table called ApplicationAccount is the following:
117
+
118
+ Controller:
119
+
120
+ @tasks_grid = initialize_grid(Task)
121
+
122
+ View:
123
+
124
+ <%= grid(@tasks_grid) do |g|
125
+
126
+ g.column do |task|
127
+ task.id
128
+ end
129
+
130
+ g.column do |task|
131
+ task.title
132
+ end
133
+
134
+ g.column do |task|
135
+ task.description
136
+ end
137
+
138
+ g.column do |task|
139
+ task.archived? ? 'Yes' : 'No'
140
+ end
141
+
142
+ g.column do |task|
143
+ link_to('Edit', edit_task_path(task))
144
+ end
145
+ end -%>
146
+
147
+ Code <tt>g.column do |task| ... end</tt>
148
+ defines everything related to a column in the resulting view table including column names, sorting, filtering, the content of the column cells, etc.
149
+ The return value of the block is the table cell content.
150
+
151
+ In the above view code five columns were defined, all without names, no sorting or filtering is available. Still, pagination becomes active if
152
+ the number of all extracted records exceeds the default number of rows per page.
153
+
154
+ Column names are defined with parameter <tt>:column_name</tt>:
155
+
156
+ <%= grid(@tasks_grid) do |g|
157
+
158
+ g.column :column_name => 'ID' do |task|
159
+ task.id
160
+ end
161
+
162
+ g.column :column_name => 'Title' do |task|
163
+ task.title
164
+ end
165
+
166
+ g.column :column_name => 'Description' do |task|
167
+ task.description
168
+ end
169
+
170
+ g.column :column_name => 'Archived' do |task|
171
+ task.archived? ? 'Yes' : 'No'
172
+ end
173
+
174
+ g.column do |task|
175
+ link_to('Edit', edit_task_path(task))
176
+ end
177
+ end -%>
178
+
179
+ To add filtering and ordering, declare to which column in the underlying database table(s) the view column corresponds using
180
+ parameter <tt>:attribute_name</tt> :
181
+
182
+ <%= grid(@tasks_grid) do |g|
183
+
184
+ g.column :column_name => 'ID', :attribute_name => 'id' do |task|
185
+ task.id
186
+ end
187
+
188
+ g.column :column_name => 'Title', :attribute_name => 'title' do |task|
189
+ task.title
190
+ end
191
+
192
+ g.column :column_name => 'Description', :attribute_name => 'description' do |task|
193
+ task.description
194
+ end
195
+
196
+ g.column :column_name => 'Archived', :attribute_name => 'archived' do |task|
197
+ task.archived? ? 'Yes' : 'No'
198
+ end
199
+
200
+ g.column do |task|
201
+ link_to('Edit', edit_task_path(task))
202
+ end
203
+ end -%>
204
+
205
+ This will add sorting links and filters for columns +Username+ and +Active+.
206
+ The plugin automatically creates filters according to the type
207
+ of the database column. In the above example a text field will be created for column Title (title is a string),
208
+ for column +Archived+ a dropdown filter will be created with options 'Yes', 'No', and '--', and for the integer ID two short text fields are
209
+ added which can contain the numeric range (more than, less than).
210
+
211
+ It is important to remember that <tt>:attribute_name</tt> is the name of the database column, not a model attribute. Of course, all database columns have corresponding model attributes, but not all model attributes map to columns in the same table with the same name.
212
+
213
+ Read more about available filters in the documentation
214
+ for the column method. Read the section about custom dropdown filters for more advanced filters.
215
+
216
+
217
+ For columns like
218
+
219
+ g.column :column_name => 'Title', :attribute_name => 'title' do |task|
220
+ task.title
221
+ end
222
+
223
+ where the block contains just a call to the same attribute declared by :attribute_name, the block can be omitted:
224
+
225
+ <%= grid(@tasks_grid) do |g|
226
+
227
+ g.column :column_name => 'ID', :attribute_name => 'id'
228
+
229
+ g.column :column_name => 'Title', :attribute_name => 'title'
230
+
231
+ g.column :column_name => 'Description', :attribute_name => 'description'
232
+
233
+ g.column :column_name => 'Archived', :attribute_name => 'archived' do |task|
234
+ task.archived? ? 'Yes' : 'No'
235
+ end
236
+
237
+ g.column do |task|
238
+ link_to('Edit', edit_task_path(task))
239
+ end
240
+ end -%>
241
+
242
+
243
+ In this case +attribute_name+ will be used as the method name to send to the ActiveRecord instance.
244
+
245
+ If only sorting is needed, we can turn off filters using <tt>:no_filter</tt> :
246
+
247
+ g.column :column_name => 'ID', :attribute_name => 'id', :no_filter => true
248
+
249
+ If no ordering links are needed, use <tt>:allow_ordering</tt>:
250
+
251
+ g.column :column_name => 'Added', :attribute_name => 'created_at', :allow_ordering => false
252
+
253
+ It is important to understand that it is up to the developer to make sure that the value returned by a column block (the content of a cell) corresponds to the underlying database column specified by <tt>:attribute_name</tt> (and <tt>:model_class</tt> discussed below).
254
+
255
+
256
+ === Rendering filter panel
257
+
258
+ The filter panel can be shown and hidden clicking the icon with binoculars.
259
+
260
+ The way the filter panel is shown after the page is loaded is controlled via parameter <tt>:show_filters</tt> of the <tt>grid</tt> helper.
261
+ Possible values are:
262
+
263
+ * <tt>:when_filtered</tt> - the filter is shown when the current table is the result of filtering
264
+ * <tt>:always</tt> - show the filter always
265
+ * <tt>:no</tt> - never show the filter
266
+
267
+ Example:
268
+
269
+ <%= grid(@tasks_grid, :show_filters => :always) do |g|
270
+ ......
271
+ end -%>
272
+
273
+
274
+ Filter related icons (filter icon, reset icon, show/hide icon) are placed in the header of the last column if
275
+ it doesn't have any filter or a column name, otherwise an additional table column is added. To always place
276
+ the icons in the additional column, set <tt>Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS</tt> to +false+ in
277
+ the configuration file.
278
+
279
+
280
+ === Initial Ordering
281
+
282
+ Initializing the grid we can also define the column by which the record will be ordered <em>on the first rendering of the grid</em>, when the user has not set their ordering setting by clicking the column label, and the order direction:
283
+
284
+ @tasks_grid = initialize_grid(Task,
285
+ :order => 'tasks.title',
286
+ :order_direction => 'desc'
287
+ )
288
+
289
+ === Records Per Page
290
+
291
+ The number of rows per page is set with <tt>:per_page</tt>:
292
+
293
+ @tasks_grid = initialize_grid(Task, :per_page => 40)
294
+
295
+ === Conditions
296
+
297
+ The +initialize_grid+ method supports a <tt>:conditions</tt> parameter which is passed on to the underlying ActiveRecord (via will_paginate), so it can be in any format processable by ActiveRecord:
298
+
299
+ @tasks_grid = initialize_grid(Task,
300
+ :conditions => ["archived = false and estimated_time > ?", 100]
301
+ )
302
+
303
+ @tasks_grid = initialize_grid(Task,
304
+ :include => :project,
305
+ :conditions => {:archived => false, :project => {:active => true}}
306
+ )
307
+
308
+
309
+
310
+ A good example is substituting a common pattern like
311
+
312
+ @user_groups = @portal_application.user_groups
313
+
314
+ with WiceGrid code:
315
+
316
+ @user_groups_grid = initialize_grid(UserGroup, :conditions => ['portal_application_id = ?', @portal_application])
317
+
318
+
319
+ === Queries with join tables
320
+
321
+ WiceGrid also supports ActiveRecord's <tt>:joins</tt> and <tt>:include</tt>.
322
+
323
+ @products_grid = initialize_grid(Product,
324
+ :include => :category,
325
+ :order => 'products.name',
326
+ :per_page => 20)
327
+
328
+ Note that if we want to order initially by a column from a joined table we have to specify the table and the column name with the sql dot notation, that is, <tt>products.name</tt>
329
+
330
+ To show columns of joined tables in the view table, the ActiveRecord model class name has to be specified, that corresponds to the joined table:
331
+
332
+ <%= grid(@products_grid) do |g|
333
+ g.column :column_name => 'Product Name', :attribute_name => 'name' do |product| # primary table
334
+ link_to(product.name, product_path(product))
335
+ end
336
+
337
+ g.column :column_name => 'Category', :attribute_name => 'name', :model_class => Category |product| # joined table
338
+ product.category.name
339
+ end
340
+ %>
341
+
342
+ Please note that the blockless definition of the column only works with columns from the main table and it won't work with columns with <tt>:model_class</tt>
343
+
344
+ === Joined associations referring to the same table
345
+
346
+ In case there are two joined associations both referring to the same table, ActiveRecord constructs a query where
347
+ the second join provides an alias for the joined table. To enable WiceGrid to order and filter by columns belonging to different associations
348
+ but originating from the same table, set <tt>:table_alias</tt> to this alias:
349
+
350
+ Model:
351
+
352
+ class Project < ActiveRecord::Base
353
+ belongs_to :customer, :class_name => 'Company'
354
+ belongs_to :supplier, :class_name => 'Company'
355
+ end
356
+
357
+ Controller:
358
+
359
+ @projects_grid = initialize_grid(Project, :include => [:customer, :supplier] )
360
+
361
+
362
+ View:
363
+
364
+ <%= grid(@projects_grid, :show_filters => :always) do |g|
365
+
366
+ g.column :column_name => 'Project Name', :attribute_name => 'name'
367
+
368
+ g.column :column_name => 'Customer company', :model_class => 'Company', :attribute_name => 'name' do |task|
369
+ task.customer.name if task.customer
370
+ end
371
+
372
+ g.column :column_name => 'Supplier company', :model_class => 'Company', :attribute_name => 'name', :table_alias => ' suppliers_projects' do |task|
373
+ task.supplier.name if task.supplier
374
+ end
375
+
376
+ end -%>
377
+
378
+
379
+ === More than one grid on a page
380
+
381
+ It is possible to use more that one grid on a page, each with its own state. To do so, you must specify the name of the grid in +initialize_grid+ using
382
+ parameter <tt>:name</tt>
383
+
384
+ The name serves as the base name for HTTP parameters, DOM IDs, etc, so it is important that all grids on a page have different names. The default
385
+ name is 'grid'.
386
+
387
+ The name can only contain alphanumeric characters.
388
+
389
+ @projects_grid = initialize_grid(Project, :name => 'g1' )
390
+ @tasks_grid = initialize_grid(Task, :name => 'g2')
391
+
392
+
393
+ === Custom Ordering
394
+
395
+ It is possible to change the way results are ordered injecting a piece of SQL code, for example, use
396
+ <tt>ORDER BY INET_ATON(ip_address)</tt> instead of <tt>ORDER BY ip_address</tt>.
397
+
398
+ To do so, provide parameter <tt>:custom_order</tt> in the initialization of the grid with a hash where keys are fully qualified names
399
+ of database columns, and values the required chunks of SQL to use in the ORDER BY clause.
400
+
401
+ For example:
402
+
403
+
404
+ @hosts_grid = initialize_grid(Host,
405
+ :custom_order => {
406
+ 'hosts.ip_address' => 'INET_ATON(hosts.ip_address)'
407
+ })
408
+
409
+
410
+ It is possible to use the '?' character instead of the name of the column in the hash value:
411
+
412
+ @hosts_grid = initialize_grid(Host,
413
+ :custom_order => {
414
+ 'hosts.ip_address' => 'INET_ATON( ? )'
415
+ })
416
+
417
+ Values can also be Proc objects. The parameter supplied to such a Proc object is the name of the column:
418
+
419
+ @hosts_grid = initialize_grid(Host,
420
+ :custom_order => {
421
+ 'hosts.ip_address' => lambda{|f| "INET_ATON( #{f} )"}
422
+ })
423
+
424
+
425
+ === Custom dropdown filters
426
+
427
+ It is possible to construct custom dropdown filters. Depending on the value of <tt>column</tt> parameter<tt>:custom_filter</tt> different
428
+ modes are available:
429
+
430
+
431
+ ==== Array of two-element arrays or a hash
432
+
433
+ An array of two-element arrays or a hash are semantically identical ways of creating a custom filter.
434
+
435
+ Every first item of the two-element array is used for the label of the select option while the second element is the value of the select option. In case of a hash the keys become the labels of the generated dropdown list, while the values will be values of options of the dropdown list:
436
+
437
+ g.column :column_name => 'Status', :attribute_name => 'status',
438
+ :custom_filter => {'Development' => 'development', 'Testing' => 'testing', 'Production' => 'production'}
439
+
440
+ g.column :column_name => 'Status', :attribute_name => 'status',
441
+ :custom_filter => [['Development', 'development'], ['Testing', 'testing'], ['Production', 'production']]
442
+
443
+ It is also possible to submit a array of strings or numbers, in this case every item will be used both as the value of the select option and as its label:
444
+
445
+ g.column :column_name => 'Status', :attribute_name => 'status',
446
+ :custom_filter => ['development', 'testing', 'production']
447
+
448
+
449
+ ==== :auto
450
+
451
+ <tt>:auto</tt> - a powerful option which populates the dropdown list with all unique values of the column specified by
452
+ <tt>:attribute_name</tt> and <tt>:model_class</tt>.
453
+
454
+ g.column :column_name => 'Status', :attribute_name => 'status',
455
+ :custom_filter => ['development', 'testing', 'production']
456
+
457
+ Note that in the above example all names of all possible categories will appear even if they don't appear in the current resultset.
458
+ To only show those which do appear in the resutset, use an array of symbol messages (see section 'An array of symbols').
459
+
460
+
461
+ ==== Custom filters and associations (joined tables)
462
+
463
+ In most cases custom fields are required for one-to-many and many-to-many associations.
464
+
465
+ To correctly build a filter condition foreign keys have to be matched.
466
+
467
+ For example, if there is a column:
468
+
469
+ g.column :column_name => 'Project Name', :attribute_name => 'name', :model_class => 'Project' do |task|
470
+ task.project.name if task.project
471
+ end
472
+
473
+ adding <tt>:custom_filter</tt> like this:
474
+
475
+ g.column :column_name => 'Project Name', :attribute_name => 'name', :model_class => 'Project',
476
+ :custom_filter => Project.find(:all).map{|pr| [pr.name, pr.name]} do |task|
477
+ task.project.name if task.project
478
+ end
479
+
480
+ is bad style and can fail, because the resulting condition will compare the name of the project, <tt>projects.name</tt> to a string,
481
+ and in some databases it is possible that different records (projects in our example) have the same name.
482
+
483
+ To use filter with foreign keys, we have to change the declaration of the column from <tt>projects.name</tt>, to
484
+ <tt>tasks.project_id</tt>, and build the dropdown with foreign keys as values:
485
+
486
+
487
+ g.column :column_name => 'Project Name', :attribute_name => 'tasks.project_id',
488
+ :custom_filter => Project.find(:all).map{|pr| [pr.id, pr.name]} do |task|
489
+ task.project.name if task.project
490
+ end
491
+
492
+ However, this will break the ordering of the column - the column will be ordered by the integer foreign key. To fix this,
493
+ we can override the ordering using <tt>:custom_order</tt>:
494
+
495
+ @tasks_grid = initialize_grid(Task,
496
+ :include => :project,
497
+ :custom_order => {
498
+ 'tasks.project_id' => 'projects.name'
499
+ }
500
+ )
501
+
502
+
503
+ ==== Any other symbol (method name) or an array of symbols (method names)
504
+
505
+
506
+ For one symbol (different from <tt>:auto</tt>) the dropdown list is populated by all unique values returned by the method with this name
507
+ sent to <em>all</em> ActiveRecord objects throughout all pages.
508
+
509
+ The conditions set up by the user are ignored, that is, the records used are all those found on all pages without any filters active.
510
+
511
+ For an array of symbols, the first method name is sent to the ActiveRecord
512
+ object if it responds to this method, the second method name is sent to the
513
+ returned value unless it is +nil+, and so on. In other words, a single symbol mode is the
514
+ same as an array of symbols where the array contains just one element.
515
+
516
+ g.column :column_name => 'Version', :attribute_name => 'expected_version_id', :custom_filter => [:expected_version, :to_option] do |task|
517
+ task.expected_version.name if task.expected_version
518
+ end
519
+
520
+
521
+ There are two important differences from <tt>:auto</tt>:
522
+
523
+ 1. The method does not have to be a field in the result set, it is just some value computed in the method after the database call and ActiveRecord instantiation.
524
+ 2. Filtering by any option of such a custom filter will bring a non-empty list, unlike with <tt>:auto</tt>.
525
+
526
+
527
+ This mode has one major drawback - this mode requires an additional query without +offset+ and +limit+ clauses to instantiate _all_
528
+ ActiveRecord objects, and performance-wise it brings all the advantages of pagination to nothing. Thus, memory- and performance-wise this can be really bad for some queries and tables and should be used with care.
529
+
530
+
531
+ If the final method returns a atomic value like a string or an integer, it is used for both the value and the label of the select option element:
532
+
533
+ <option value="returned value">returned value</option>
534
+
535
+ However, if the retuned value is a two element array, the first element is used for the option label and the second - for the value.
536
+
537
+ Typically, a model method like the following:
538
+
539
+ def to_option
540
+ [name, id]
541
+ end
542
+
543
+ together with
544
+
545
+ :custom_filter => :to_option
546
+
547
+ would do the trick:
548
+
549
+ <option value="id">name</option>
550
+
551
+ Alternatively, a hash with the single key-value pair can be used, where the key will be used for the label, and the key - for the value:
552
+
553
+ def to_option
554
+ {name => id}
555
+ end
556
+
557
+
558
+ ==== Special treatment of values 'null' and 'not null'
559
+
560
+ Values 'null' and 'not null' in a generated custom filter are treated specially, as SQL +null+ statement and not as strings.
561
+ Value 'null' is transformed into SQL condition <tt>IS NULL</tt>, and 'not null' into <tt>IS NOT NULL</tt>
562
+
563
+ Thus, if in a filter defined by
564
+ :custom_filter => {'No' => 'null', 'Yes' => 'not null', '1' => 1, '2' => '2', '3' => '3'}
565
+ values '1', '2' and 'No' are selected (in a multi-select mode), this will result in the following SQL:
566
+
567
+ ( table.field IN ( '1', '2' ) OR table.field IS NULL )
568
+
569
+
570
+ ==== Multiple selection
571
+
572
+ By default it is possible for any dropdown list to switch between single and multiple selection modes. To only allow
573
+ single selection use <tt>:allow_multiple_selection</tt>:
574
+
575
+
576
+ g.column :column_name => 'Expected in version', :attribute_name => 'expected_version_id',
577
+ :custom_filter => [:expected_version, :to_option], :allow_multiple_selection => false do |task|
578
+ ...
579
+ end
580
+
581
+
582
+ === Defaults
583
+
584
+ Default values like can be changed in <tt>config/initializers/wice_grid_config.rb</tt>, as well grid labels and paths to some images.
585
+
586
+
587
+
588
+ === Submit/Reset buttons
589
+ View helper +submit_grid_javascript+ returns javascript which applies current filters.
590
+ View helper +reset_grid_javascript+ returns javascript which resets the grid, clearing the state of filters.
591
+ This allows to create your own Submit and Reset buttons anywhere on the page with the help of +button_to_function+:
592
+
593
+ <%= button_to_function "Submit", submit_grid_javascript(@grid) %>
594
+ <%= button_to_function "Reset", reset_grid_javascript(@grid) %>
595
+
596
+ To complement this feature there are two parameters in the +grid+ helper <tt>:hide_submit_button</tt> and <tt>:hide_reset_button</tt> which
597
+ hide default buttons in the grid if set to true.
598
+
599
+
600
+ === Auto-reloading filters
601
+
602
+ It is possible to configure a grid to reload itself once a filter has been changed. It works with all
603
+ filter types including the JS calendar, the only exception is the standard Rails date/datetime filters.
604
+
605
+ Use option <tt>:auto_reload</tt> in the column definiton:
606
+
607
+
608
+ <%= grid(@tasks_grid, :show_filters => :always, :hide_submit_button => true) do |g|
609
+
610
+ # String
611
+ g.column :column_name => 'Title', :attribute_name => 'title', :auto_reload => true
612
+
613
+ # Boolean
614
+ g.column :column_name => 'Archived', :attribute_name => 'archived', :auto_reload => true
615
+
616
+ # Custom (dropdown)
617
+ g.column :column_name => 'Status', :attribute_name => 'status_id', :custom_filter => Status.to_dropdown, :auto_reload => true do |task|
618
+ task.status.name if task.status
619
+ end
620
+
621
+ # Datetime
622
+ g.column :column_name => 'Added', :attribute_name => 'created_at', :auto_reload => true, :helper_style => :calendar do |task|
623
+ task.created_at.to_s(:short)
624
+ end
625
+
626
+ end -%>
627
+
628
+ To make this behavior default change constant +AUTO_RELOAD+ in the configuration file.
629
+
630
+ === Styling the grid
631
+
632
+ ==== Predefined css classes used by the grid
633
+
634
+ +td+ tags are assigned two styles automatically - +sorted+ if the column is the one by which the grid is ordered,
635
+ and +active_filter+ if the column's filter is on.
636
+
637
+ Odd and even +tr+ tags are assigned styles +odd+ and +even+, correspondingly.
638
+
639
+ For other classes see <tt>wice_grid.css</tt>. Feel free to customize it according to your needs.
640
+
641
+ ==== Adding classes and styles
642
+
643
+ The +grid+ helper accepts parameter <tt>:table_html_attrs</tt> which is a hash of HTML
644
+ attributes for the table tag.
645
+
646
+ Another +grid+ parameter is <tt>header_tr_html_attrs</tt> which is a hash of HTML attributes to be added to the first +tr+ tag (or two first +tr+'s if the filter row is present).
647
+
648
+ <tt>:td_html_attrs</tt> is a parameter for the +column+ method setting HTML attributes of +td+ tags for a certain column.
649
+
650
+ ==== Adding classes and styles dynamically
651
+
652
+ WiceGrid offers ways to dynamically add classes and styles to +TR+ and +TD+ based on the current ActiveRecord instance.
653
+
654
+
655
+ For <tt><TD></tt>, let the +column+ return an array where the first item is the usual
656
+ string output whole the second is a hash of HTML attributes to be added for the <tt><td></tt> tag of the current cell:
657
+
658
+ g.column do |portal_application|
659
+ css_class = portal_application.public? ? 'public' : 'private'
660
+ [portal_application.name, {:class => css_class}]
661
+ end
662
+
663
+ For adding classes/styles to <tt><TR></tt> use special clause +row_attributes+ , similar to +column+, only returning a hash:
664
+
665
+ <%= grid(@versions_grid) do |g|
666
+ g.row_attributes do |version|
667
+ if version.in_production?
668
+ {:style => 'background-color: rgb(255, 255, 204);'}
669
+ end
670
+ end
671
+
672
+ g.column{|version| ... }
673
+ g.column{|version| ... }
674
+ end -%>
675
+
676
+ Naturally, there can be only one +row_attributes+ definition for a WiceGrid instance.
677
+
678
+ Various classes do not overwrite each other, instead, they are concatenated.
679
+
680
+ WiceGrid icons are in directory <tt>public/images/icons/grid/</tt>.
681
+
682
+
683
+ === Adding rows to the grid
684
+
685
+ It is possible to add your own handcrafted HTML after and/or before each grid row. This works similar to +row_attributes+, by adding blocks +after_row+ and +before_row+:
686
+
687
+ <%= grid(@tasks_grid) do |g|
688
+ g.before_row do |task|
689
+ if task.active?
690
+ "<tr><td colspan=\"10\">Custom line for #{t.name}</td></tr>" # this would add a row
691
+ # before every active task row
692
+ else
693
+ nil
694
+ end
695
+ end
696
+ .......
697
+ end %>
698
+
699
+ It is up for the developer to return the correct HTML code, or return +nil+ if no row is needed for this record. Naturally, there is only one +before_row+ definition and one +after_row+ definition for a WiceGrid instance.
700
+
701
+ A real life example might be some enterprisy tables inside a table.
702
+
703
+ === Rendering a grid without records
704
+
705
+ If the grid does not contain any records to show, it is possible show some alternative view instead of an empty grid. Bear in mind that if the user
706
+ sets up the filters in such a way that the selection of records is empty, this will still render the grid and it will be possible to
707
+ reset the grid clicking on the Reset button. Thus, this only works if the initial number of records is 0.
708
+
709
+ <%= grid(@grid) do |g|
710
+
711
+ g.blank_slate do
712
+ "There are no records"
713
+ end
714
+
715
+ g.column do |product|
716
+ ...
717
+ end
718
+ end -%>
719
+
720
+ There are two alternative ways to do the same, submitting a string to +blank_slate+:
721
+
722
+ g.blank_slate "some text to be rendered"
723
+
724
+ Or a partial:
725
+
726
+ g.blank_slate :partial => "partial_name"
727
+
728
+
729
+ === Localization
730
+
731
+ Versions of WiceGrid newer than version 0.5 support localization via Rails I18n, however, without breaking
732
+ compatibility with pre-I18n versions of Rails (2.1.0 and older).
733
+
734
+ Running
735
+
736
+ ./script/generate wice_grid_assets
737
+
738
+ will copy file <tt>wice_grid.yml</tt> to <tt>config/locales</tt>.
739
+
740
+ The current locale is taken from <tt>I18n.locale</tt>. The locale also propagates to the javascript calendar
741
+ widget (see <tt>Calendar.messagebundle</tt> in <tt>calendarview.js</tt> to add languages).
742
+
743
+ If the messages are not found, or I18n is missing, WiceGrid will fall back to the hardcoded messages in
744
+ <tt>config/initializers/wice_grid_config.rb</tt>.
745
+
746
+ Currently supported languages are English, Dutch, French, and Russian.
747
+
748
+ === ERB mode
749
+
750
+ The view helper can function in two different modes. These are defined by its +erb_mode+ parameter.
751
+ By default (<tt>:erb_mode => false</tt>) the view helper is a simple helper surrounded by <tt><%=</tt> and <tt>%></tt>, like in all examples
752
+ above.
753
+
754
+
755
+ The second mode (<tt>:erb_mode => true</tt>) is called <em>ERB mode</em> and it allows to embed any ERB content inside blocks,
756
+ which is basically the style of the
757
+ <tt>form_for</tt> helper, only <tt>form_for</tt> takes one block, while inside the <tt>grid</tt> block there are other method calls taking
758
+ blocks as parameters:
759
+
760
+ <% grid(@countries_grid, :erb_mode => true) do |g| %>
761
+
762
+ <% g.column :column_name => 'Name', :attribute_name => 'name' do |country| %>
763
+ <b>Name: <%= link_to(country.name, country_path(country)) %></b>
764
+ <% end %>
765
+
766
+ <% g.column :column_name => 'Numeric Code', :attribute_name => 'numeric_code' do |country| %>
767
+ <i>Numeric Code: <%= country.numeric_code %></i>
768
+ <% end %>
769
+
770
+ <% end -%>
771
+
772
+ This mode can be usable if you like to have much HTML code inside cells.
773
+
774
+ Please remember that in this mode the helper opens with <tt><%</tt> instead of <tt><%=</tt>, similar to <tt>form_for</tt>.
775
+
776
+ The default value for <tt>:show_filters</tt> can be changed in <tt>config/initializers/wice_grid_config.rb</tt>.
777
+
778
+ === Action Column
779
+
780
+ It is easy to add a column with checkboxes for each record. This is useful for actions with multiple records,
781
+ for example, deleting selected records. Please note that +action_column+ only creates the checkboxes and the
782
+ 'Select All' and 'Deselect All' buttons, and the form itself as well as processing the parameters should be
783
+ taken care of by the application code.
784
+
785
+ <%= grid(@tasks_grid, :show_filters => :always) do |g|
786
+
787
+ ...
788
+
789
+ g.action_column
790
+
791
+ ...
792
+
793
+ end -%>
794
+
795
+ By default the name of the HTTP parameter follows pattern <tt>"#{grid_name}[#{param_name}][]"</tt>, thus
796
+ <tt>params[grid_name][param_name]</tt> will contain an array of object IDs.
797
+
798
+ See the documentation for more details.
799
+
800
+
801
+ === Integration of the grid with other forms on page
802
+
803
+ Imagine that the user should be able to change the behavior of the grid using some other control on the page, and not a grid filter.
804
+
805
+ For example, on a page showing tasks,
806
+ change between 'Show active tasks' to 'Show archived tasks' using a dropdown box.
807
+ WiceGrid allows to keep the status of the grid with all the filtering and sorting
808
+ using helper +dump_filter_parameters_as_hidden_fields+ which takes a grid object and dumps all current sorting and filtering parameters as
809
+ hidden fields. Just include <tt>dump_filter_parameters_as_hidden_fields(@grid)</tt> inside your form, and the newly rendered grid will
810
+ keep ordering and filtering.
811
+
812
+ <% form_tag('', :method => :get) do %>
813
+ <%= dump_filter_parameters_as_hidden_fields(@tasks_grid) %>
814
+ <%= select_tag 'archived',
815
+ options_for_select([['View active tasks', 0], ['View archived tasks', 1]], @archived ? 1 : 0),
816
+ :onchange => 'this.form.submit()' %>
817
+ <% end -%>
818
+
819
+
820
+ === Javascript Calendar for Date and DateTime Filters.
821
+
822
+ Standard Rails Date and DateTime helpers are a set of dropdown lists, and while this is practical,
823
+ displaying two Date or especially DateTime
824
+ helpers takes too much space on a page and is in general confusing.
825
+
826
+ To solve this, WiceGrid includes a second variant of Date/DateTime filters based on a Javascript calendar.
827
+
828
+ In the Prototype mode the plugin uses a forked[http://github.com/leikind/calendarview] version of Calendarview[http://github.com/jsmecham/calendarview]. It is bundled with the plugin and the generator task
829
+ +wice_grid_assets_prototype+ will install al necessary assets.
830
+
831
+ The jQuery version uses jQuery datepicker[http://jqueryui.com/demos/datepicker/]. Because this is part
832
+ of the standard jQuery codebase, it is not bundled together with the plugin, and it is the responsibility
833
+ of the programmer to include all necessary assets including localization files if the application is
834
+ multilingual.
835
+
836
+ It is always possible to fall back to simple dropdown lists that the standard date/datetime Rails helpers use.
837
+
838
+ JQUERY DATEPICKER IS ONLY USED FOR DATE FILTERS AT THE MOMENT. DATETIME FILTERS FALL BACK TO THE DEFAULT
839
+ RAILS DATE/DATETIME HELPERS.
840
+
841
+
842
+ Calendar based helpers are enabled by default, but it's possible to change it in
843
+ <tt>config/initializers/wice_grid_config.rb</tt>, variable HELPER_STYLE.
844
+
845
+ The flavor of the date filter can also be changed on per-column basis:
846
+
847
+ g.column :column_name => 'Due Date', :attribute_name => 'due_date', :helper_style => :calendar do |task|
848
+ task.due_date.to_s(:short) if task.due_date
849
+ end
850
+
851
+ g.column :column_name => 'Updated', :attribute_name => 'updated_at', :helper_style => :standard do |task|
852
+ task.created_at.to_s(:short)
853
+ end
854
+
855
+ Constants +DATE_FORMAT+ and +DATETIME_FORMAT+ define the format of dates the user will see, as well as the
856
+ format of the string sent in a HTTP parameter.
857
+
858
+ You can change the constants in
859
+ <tt>config/initializers/wice_grid_config.rb</tt>. Doing so, make sure that lamdbas defined
860
+ in +DATETIME_PARSER+ and +DATE_PARSER+ return valid DateTime and Date objects. The format
861
+ by default is <tt>%Y-%m-%d</tt> for the Date and the date part of DateTime, and <tt>Time.zone.parse</tt>
862
+ and <tt>Date.parse</tt> handle it.
863
+ Make sure it stays so.
864
+
865
+ jQuery +datepicker+ uses a different format flavor, therefore there is an additional constant
866
+ +DATE_FORMAT_JQUERY+. While +DATE_FORMAT_JQUERY+ is fed to +datepicker+, +DATE_FORMAT+ is still used
867
+ for presenting initial date values in filters, so make sure that +DATE_FORMAT_JQUERY+ and +DATE_FORMAT+
868
+ result in an identical date representation.
869
+
870
+
871
+ === Show All Records
872
+
873
+ It is possible to switch to the All Records mode clicking on link "show all" in the bottom right corner. This functionality should be used
874
+ with care. To turn this mode off for all grid instances, change constant +ALLOW_SHOWING_ALL_QUERIES+ in
875
+ <tt>config/initializers/wice_grid_config.rb</tt> to
876
+ +false+. To do so for a specific grid, use initializer parameter <tt>:allow_showing_all_records</tt>.
877
+
878
+ Configuration constant +START_SHOWING_WARNING_FROM+ sets the threshold number of all records after which clicking on the
879
+ link results in a javascript confirmation dialog.
880
+
881
+
882
+ === CSV Export
883
+
884
+ It is possible to export the data displayed on a grid to a CSV file. The dumped data is the current resultset with all the
885
+ current filters and sorting applied, only without the pagination constraint (i.e. all pages).
886
+
887
+ To enable CSV export add parameters +enable_export_to_csv+ and +csv_file_name+ to the initialization of the grid:
888
+
889
+ @projects_grid = initialize_grid(Project,
890
+ :include => [:customer, :supplier],
891
+ :name => 'g2',
892
+ :enable_export_to_csv => true,
893
+ :csv_file_name => 'projects'
894
+ )
895
+
896
+ +csv_file_name+ is the name of the downloaded file. This parameter is optional, if it is missing, the name of the grid is used instead.
897
+ The export icon will appear at the bottom right corner of the grid.
898
+
899
+ Next, each grid view helper should be placed in a partial of its own, requiring it from the master template for the usual flow. There must be no
900
+ HTML or ERB code in this partial except for the grid helper.
901
+
902
+ By convention the name of such a partial follows the following pattern:
903
+
904
+ _GRID_NAME_grid.html.erb
905
+
906
+ In other words, a grid named +tasks+ is expected to be found in a template called <tt>_tasks_grid.html.erb</tt> (remember that the default name of grids is '+grid+'.)
907
+
908
+ Next, method +export_grid_if_requested+ should be added to the end of each action containing grids with enabled CSV export.
909
+
910
+ +export_grid_if_requested+ intercepts CSV export requests and evaluates the partial with the required grid helper.
911
+
912
+ The naming convention for grid partials can be easily overridden by supplying a hash parameter to +export_grid_if_requested+
913
+ where each key is the name of a grid, and the value is the name of the template (like it is specified for +render+, i.e.
914
+ without '_' and extensions):
915
+
916
+
917
+ export_grid_if_requested('g1' => 'tasks_grid', 'g2' => 'projects_grid')
918
+
919
+ If the request is not a CSV export request, +export_grid_if_requested+ does nothing and returns +false+, if it is a CSV export request,
920
+ the method returns +true+.
921
+
922
+
923
+ If the action has no explicit +render+ call, it's OK to just place +export_grid_if_requested+ as the last line of the action:
924
+
925
+ def index
926
+
927
+ @tasks_grid = initialize_grid(Task,
928
+ :name => 'g1',
929
+ :enable_export_to_csv => true,
930
+ :csv_file_name => 'tasks'
931
+ )
932
+
933
+ @projects_grid = initialize_grid(Project,
934
+ :name => 'g2',
935
+ :enable_export_to_csv => true,
936
+ :csv_file_name => 'projects'
937
+ )
938
+
939
+ export_grid_if_requested
940
+ end
941
+
942
+
943
+ Otherwise, to avoid double rendering, use the return value of the method to conditionally call your +render+ :
944
+
945
+
946
+ def index
947
+
948
+ ...........
949
+
950
+ export_grid_if_requested || render(:action => 'my_template')
951
+ end
952
+
953
+
954
+ It's also possible to supply a block which will be called if no CSV export is requested:
955
+
956
+ def index
957
+
958
+ ...........
959
+
960
+ export_grid_if_requested do
961
+ render(:action => 'my_template')
962
+ end
963
+ end
964
+
965
+
966
+ If a column has to be excluded from the CSV export,
967
+ set +column+ parameter +in_csv+ to +false+:
968
+
969
+ g.column :in_csv => false do |task|
970
+ link_to('Edit', edit_task_path(task))
971
+ end
972
+
973
+ If a column must appear both in HTML and CSV, but with different output,
974
+ duplicate the column and use
975
+ parameters +in_csv+ and +in_html+ to include one of them to html output only, the other to CSV only:
976
+
977
+
978
+ # html version
979
+ g.column :column_name => 'Title', :attribute_name => 'title', :in_csv => false do |task|
980
+ link_to('Edit', edit_task_path(task.title))
981
+ end
982
+ # plain text version
983
+ g.column :column_name => 'Title', :in_html => false do |task|
984
+ task.title
985
+ end
986
+
987
+ The default field separator in generated CSV is a comma, but it's possible to override this submitting a
988
+ string to the <tt>:enable_export_to_csv</tt> parameter:
989
+
990
+ @products_grid = initialize_grid(Product,
991
+ :enable_export_to_csv => ';',
992
+ :csv_file_name => 'products')
993
+
994
+
995
+ === Detached Filters
996
+
997
+ It is possible to detach filters and place them anywhere on the page. To do so, use parameter <tt>:detach_with_id</tt> for a column whose filter needs to be detached, with an arbitrary string or a symbol value which will be used later to identify the filter. As soon as there is one column with <tt>:detach_with_id</tt>, the behavior of the +grid+ helper changes - it becomes an <i>initializer</i> of the grid and doesn't output any HTML code. To render the grid, use <tt>grid</tt> for the second time without the block. To render a detached output filter, use helper <tt>grid_filter(grid_object, detached_filter_key)</tt>:
998
+
999
+ <%= grid(@tasks_grid, :show_filters => :always) do |g|
1000
+
1001
+ g.column :column_name => 'Title', :attribute_name => 'title', :detach_with_id => :title_filter do |task|
1002
+ link_to('Edit', edit_task_path(task.title))
1003
+ end
1004
+
1005
+ g.column :column_name => 'Archived', :attribute_name => 'archived', :detach_with_id => :archived_filter do |task|
1006
+ task.archived? ? 'Yes' : 'No'
1007
+ end
1008
+
1009
+ g.column :column_name => 'Added', :attribute_name => 'created_at', :detach_with_id => :created_at_filter do |task|
1010
+ task.created_at.to_s(:short)
1011
+ end
1012
+
1013
+ end -%>
1014
+
1015
+ <% # rendering filter with key :title_filter %>
1016
+ <%= grid_filter @tasks_grid, :title_filter %>
1017
+
1018
+ <% # rendering filter with key :archived_filter %>
1019
+ <%= grid_filter @tasks_grid, :archived_filter %>
1020
+
1021
+ <% # rendering filter with key :created_at_filter %>
1022
+ <%= grid_filter @tasks_grid, :created_at_filter %>
1023
+
1024
+ <% # Rendering the grid body %>
1025
+ <%= grid(@tasks_grid) %>
1026
+
1027
+ It is important that the grid initializer goes first, the order of +grid_filter+ and the second call to +grid+ is of no importance.
1028
+
1029
+ Using custom submit and reset buttons together with <tt>:hide_submit_button => true</tt> and <tt>:hide_reset_button => true</tt>
1030
+ allows to completely get rid
1031
+ of the default filter row and the default icons (see section 'Submit/Reset Buttons').
1032
+
1033
+ For CSV export will continue functioning, just make sure the first call to +grid+ is still in the template of its own and
1034
+ is inside of <tt><%= %></tt>, because when CSV is requested, the first +grid+ works in the old fashioned way producing CSV formatted output.
1035
+
1036
+ This feature also works with <tt>:erb_mode => true</tt>.
1037
+
1038
+ If a column was declared with <tt>:detach_with_id</tt>, but never output with +grid_filter+, filtering the grid in development mode will result
1039
+ in an warning javascript message and the missing filter will be ignored. There is no such message in production.
1040
+
1041
+ <tt>grid</tt> parameter <tt>:show_filter</tt> must not be set to <tt>:no</tt> for detached filters to work.
1042
+
1043
+ ==== How Does It Work? (For the interested)
1044
+
1045
+ When there is at least one column with <tt>:detach_with_id</tt>, the generated HTML code is stored in a buffer, code for detached filters is stored
1046
+ in buffers of their own identified by the given IDs, and nothing is returned to the view.
1047
+ When the helper is called for the second time, the buffer outputs its content.
1048
+ In a similar fashion, the +grid_filter+ helper outputs buffers for filters.
1049
+
1050
+ === Compatibility with Rails Asset Caching
1051
+
1052
+ Helpers +names_of_wice_grid_stylesheets+ and +names_of_wice_grid_javascripts+ return names of stylesheet and javascript files and can be used with
1053
+ +stylesheet_link_tag+ and +javascript_include_tag+ with <tt>:cache => true</tt>.
1054
+ Using this trick you have to deal with the parameters correctly, mind that Prototype has to be loaded before WiceGrid javascripts:
1055
+
1056
+ <%= stylesheet_link_tag *(['core', 'modalbox'] + names_of_wice_grid_stylesheets + [ {:cache => true}]) %>
1057
+ <%= javascript_include_tag *([:defaults] + names_of_wice_grid_javascripts + [ 'ui', 'swfobject', {:cache => true}]) %>
1058
+
1059
+
1060
+ === Access to Records From Outside The Grid
1061
+
1062
+ There are two ways you can access the records outside the grid - using methods of the WiceGrid object and using callbacks.
1063
+
1064
+ ==== Accessing Records Via The WiceGrid Object
1065
+
1066
+ Method +current_page_records+ returns exactly the same list of objects displayed on page:
1067
+
1068
+ <%= grid(@tasks_grid) do |g|
1069
+ ...
1070
+ end -%>
1071
+
1072
+ <p>
1073
+ IDs of records on the current page:
1074
+ <%= @tasks_grid.current_page_records.map(&:id).to_sentence %>
1075
+ </p>
1076
+
1077
+ Method +all_pages_records+ returns a list of objects browsable through all pages with the current filters:
1078
+
1079
+ <%= grid(@tasks_grid) do |g|
1080
+ ...
1081
+ end -%>
1082
+
1083
+ <p>
1084
+ IDs of all records:
1085
+ <%= @tasks_grid.all_pages_records.map(&:id).to_sentence %>
1086
+ </p>
1087
+
1088
+ Mind that this helper results in an additional SQL query.
1089
+
1090
+
1091
+ Because of the current implementation of WiceGrid these helpers work only after the declaration of the grid in the view.
1092
+ This is due to the lazy nature of WiceGrid - the actual call to the database is made during the execution of
1093
+ the +grid+ helper, because to build the correct query columns declarations are required.
1094
+
1095
+ ==== Accessing Records Via Callbacks
1096
+
1097
+ It is possible to set up callbacks which are executed from within the plugin just after the call to the database.
1098
+ The callbacks are called before rendering the grid cells, so the results of this processing can be used in the grid.
1099
+ There are 3 ways you can set up such callbacks:
1100
+
1101
+ Via a lambda object:
1102
+
1103
+ def index
1104
+ @tasks_grid = initialize_grid(Task,
1105
+ :with_paginated_resultset => lambda do |records|
1106
+ ...
1107
+ end
1108
+ )
1109
+ end
1110
+
1111
+ Via a symbol which is the name of a controller method:
1112
+
1113
+ def index
1114
+ @tasks_grid = initialize_grid(Task,
1115
+ :with_paginated_resultset => :process_selection
1116
+ )
1117
+ end
1118
+
1119
+ def process_selection(records)
1120
+ ...
1121
+ end
1122
+
1123
+ Via a separate block:
1124
+
1125
+ def index
1126
+ @tasks_grid = initialize_grid(Task)
1127
+
1128
+ @tasks_grid.with_paginated_resultset do |records|
1129
+ ...
1130
+ end
1131
+ end
1132
+
1133
+ There are two callbacks:
1134
+
1135
+ * <tt>:with_paginated_resultset</tt> - used to process records of the current page
1136
+ * <tt>:with_resultset</tt> - used to process all records browsable through all pages with the current filters
1137
+
1138
+ While the <tt>:with_paginated_resultset</tt> callback just receives the list of records, <tt>:with_resultset</tt>
1139
+ receives a lambda object which, when called, returns the list of all records:
1140
+
1141
+
1142
+ def index
1143
+ @tasks_grid = initialize_grid(Task)
1144
+
1145
+ @tasks_grid.with_resultset do |wrapper|
1146
+ all_records = wrapper.call
1147
+ ...
1148
+ end
1149
+ end
1150
+
1151
+
1152
+ This lazy nature exists for performance reasons.
1153
+ Reading all records leads to an additional call, and there can be cases when processing all records should be triggered
1154
+ only under certain circumstances:
1155
+
1156
+ def index
1157
+ @tasks_grid = initialize_grid(Task)
1158
+
1159
+ @tasks_grid.with_resultset do |wrapper|
1160
+ if params[:process_all_records]
1161
+ all_records = wrapper.call
1162
+ ...
1163
+ end
1164
+ end
1165
+ end
1166
+
1167
+
1168
+
1169
+ == Icons
1170
+
1171
+ Icons used by the plugin are courtesy of Mark James, the creator of the SILK icon set -
1172
+ http://www.famfamfam.com/lab/icons/silk/.