wice_grid 3.4.2 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b4f8c73e81d3adc0ee032f88f103b1518f89433
4
+ data.tar.gz: 05867ac703ad3b4b8e8e90d88bcb4edd718c34e8
5
+ SHA512:
6
+ metadata.gz: a105793df1b9c11d0929beb9cd7c520cd065701ea9a11d76a78bf2f953a6cb5b8e1f17e7ae14ebe578b1bc3b4607af799a2e404e9e54c118a832c78241a98b4b
7
+ data.tar.gz: 6b9d1a057d0bbc71e90c077cb6ffafa755434107e32a07942a32f2f3bbfa9d72935b172469d542d1e79d5c0c855fc0cbe7a4430ffa563d6d077b784ff1a41711
data/CHANGELOG CHANGED
@@ -1,11 +1,40 @@
1
- 4.0.1
1
+ 3.5.0
2
+
3
+ External columns processors
4
+
5
+ Operators '<','>','<=','>=','=' in the integer column
6
+
7
+ Bugfixes
8
+
9
+ 3.4.1
2
10
 
3
11
  Support for Bootstrap 3
4
12
 
5
- 4.0.0
13
+ 3.4.0
6
14
 
7
15
  Support for Rails 4
8
16
 
17
+ 3.3.0
18
+
19
+ The with_paginated_resultset callback receives an ActiveRelation object, not a lambda
20
+
21
+ Wice::Defaults::DATEPICKER_YEAR_RANGE added to the config to define the default year range in Datepicker (https://github.com/leikind/wice_grid/issues/61)
22
+
23
+ Improvement of the javascript calendar control: if the FROM field is set to a value after TO, TO is set to the value of FROM.
24
+ Vice versa: if the TO field is set to a value before FROM, FROM is set to the value of TO
25
+
26
+ New view helpers filter_and_order_state_as_hash(grid) and filter_state_as_hash(grid)
27
+
28
+ HTML tag caption supported
29
+
30
+ Support for Ruby 2.0
31
+
32
+ 2 errors fixed in the Saved Queries UI ( https://github.com/leikind/wice_grid/issues/89 )
33
+
34
+ Bug fixed: extra_request_parameters not propagating to the pagination panel
35
+
36
+ Documentation improvements
37
+
9
38
  3.2.2
10
39
 
11
40
  improvement of the javascript calendar control: if the FROM field is set to a value after TO, TO is set to the value of FROM.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Yuri Leikind & the WICE team (http://wice.eu)
1
+ Copyright (c) 2008-2014 Yuri Leikind
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,17 +1,20 @@
1
1
  = WiceGrid
2
2
 
3
- Version:: 3.4.0
3
+ Version:: 3.4.2
4
4
  Author:: Yuri Leikind
5
5
  Sources:: https://github.com/leikind/wice_grid/
6
6
  Examples online:: http://wicegrid.herokuapp.com
7
- News:: http://leikind.org/pages/wicegrid/
7
+ News:: http://leikind.org/tag/wicegrid/
8
8
  Email:: "Yuri Leikind" <yuri.leikind at gmail dot com>
9
9
 
10
- FOR RAILS 2 USE VERSION 0.6 (https://github.com/leikind/wice_grid/tree/master).
11
10
 
12
- FOR RAILS 3 USE VERSION 3.3.x
11
+ The main supported branch is +rails3+.
13
12
 
14
- FOR RAILS 4 USE VERSION 3.4.x. However with WiceGrid 3.4.0 Rails 4 produdes the following deprecation message:
13
+ For rails 2 use the +master+ branch: https://github.com/leikind/wice_grid/tree/master
14
+
15
+ Rails 4 is supported beginning with version 3.4.x.
16
+
17
+ However, with WiceGrid 3.4.0 Rails 4 produces the following deprecation message:
15
18
 
16
19
  DEPRECATION WARNING: It looks like you are eager loading table(s) (one of: tasks, statuses) that are referenced in a string SQL snippet. For example:
17
20
 
@@ -23,6 +26,8 @@ FOR RAILS 4 USE VERSION 3.4.x. However with WiceGrid 3.4.0 Rails 4 produdes the
23
26
 
24
27
  This will be fixed in future versions of WiceGrid.
25
28
 
29
+
30
+
26
31
  == Intro
27
32
 
28
33
  WiceGrid is a Rails grid plugin.
@@ -52,15 +57,13 @@ WiceGrid does not use AJAX calls to reload itself, instead simple GET requests a
52
57
  nevertheless, all other page parameters are respected and preserved.
53
58
  WiceGrid views do not contain forms so you can include it in your own forms.
54
59
 
55
- There are two major branches of WiceGrid.
56
-
57
60
  WiceGrid is known to work with MySQL and Postgres.
58
61
 
59
62
  === Examples
60
63
 
61
64
  This tutorial is accompanied by a sample application with WiceGrid examples which you
62
- can browse online ( http://wicegrid.herokuapp.com ),
63
- or just view the code ( https://github.com/leikind/wice_grid_testbed ).
65
+ can browse online: http://wicegrid.herokuapp.com,
66
+ or just view the code: https://github.com/leikind/wice_grid_testbed.
64
67
 
65
68
 
66
69
  == Requirements
@@ -69,23 +72,24 @@ Rails version 3.2.x or newer, jQuery, jQuery Datepicker.
69
72
  For Rails 3.0.x and 3.1.x versions use version 3.0.4.
70
73
  For Rails 2 use version 0.6 (https://github.com/leikind/wice_grid/tree/master).
71
74
 
72
- WARNING: Since 3.2.pre2 WiceGrid is not compatible with <tt>will_paginate</tt> because internally it uses <tt>kaminari</tt> for pagination, and <tt>kaminari</tt> is not compatible with <tt>will_paginate</tt>!
75
+ WARNING: Since 3.2.pre2 WiceGrid is not compatible with <tt>will_paginate</tt> because internally it
76
+ uses <tt>kaminari</tt> for pagination, and <tt>kaminari</tt> is not compatible with <tt>will_paginate</tt>!
77
+
73
78
 
74
- == How-To
75
79
 
76
80
 
77
- === Support for javascript frameworks
81
+ == Support for javascript frameworks
78
82
 
79
83
  WiceGrid started as a plugin using the Prototype javascript framework.
80
84
  Support for jQuery was added for version 0.6.
81
85
  Beginning from version 3.2 only jQuery is supported.
82
86
 
83
87
 
84
- === Installation
88
+ == Installation
85
89
 
86
90
  Add the following to your Gemfile:
87
91
 
88
- gem "wice_grid", '3.2.1'
92
+ gem "wice_grid", '3.4.2'
89
93
 
90
94
  and run the <tt>bundle</tt> command.
91
95
 
@@ -118,7 +122,7 @@ but if the application uses Twitter Bootstrap, the markup generated by WiceGrid
118
122
  Generally it is advised to modify WiceGrid css to match the application style.
119
123
 
120
124
 
121
- === Basics
125
+ == Basics
122
126
 
123
127
  The simplest example of a WiceGrid for one simple DB table called ApplicationAccount is the following:
124
128
 
@@ -164,23 +168,23 @@ Column names are defined with parameter <tt>:name</tt>:
164
168
 
165
169
  <%= grid(@tasks_grid) do |g|
166
170
 
167
- g.column :name => 'ID' do |task|
171
+ g.column name: 'ID' do |task|
168
172
  task.id
169
173
  end
170
174
 
171
- g.column :name => 'Title' do |task|
175
+ g.column name: 'Title' do |task|
172
176
  task.title
173
177
  end
174
178
 
175
- g.column :name => 'Description' do |task|
179
+ g.column name: 'Description' do |task|
176
180
  task.description
177
181
  end
178
182
 
179
- g.column :name => 'Archived' do |task|
183
+ g.column name: 'Archived' do |task|
180
184
  task.archived? ? 'Yes' : 'No'
181
185
  end
182
186
 
183
- g.column do |task|
187
+ g.column do |task|
184
188
  link_to('Edit', edit_task_path(task))
185
189
  end
186
190
  end -%>
@@ -190,23 +194,23 @@ table(s) the view column corresponds using parameter <tt>:attribute</tt> :
190
194
 
191
195
  <%= grid(@tasks_grid) do |g|
192
196
 
193
- g.column :name => 'ID', :attribute => 'id' do |task|
197
+ g.column name: 'ID', attribute: 'id' do |task|
194
198
  task.id
195
199
  end
196
200
 
197
- g.column :name => 'Title', :attribute => 'title' do |task|
201
+ g.column name: 'Title', attribute: 'title' do |task|
198
202
  task.title
199
203
  end
200
204
 
201
- g.column :name => 'Description', :attribute => 'description' do |task|
205
+ g.column name: 'Description', attribute: 'description' do |task|
202
206
  task.description
203
207
  end
204
208
 
205
- g.column :name => 'Archived', :attribute => 'archived' do |task|
209
+ g.column name: 'Archived', attribute: 'archived' do |task|
206
210
  task.archived? ? 'Yes' : 'No'
207
211
  end
208
212
 
209
- g.column do |task|
213
+ g.column do |task|
210
214
  link_to('Edit', edit_task_path(task))
211
215
  end
212
216
  end -%>
@@ -231,7 +235,7 @@ Read the section about custom dropdown filters for more advanced filters.
231
235
 
232
236
  For columns like
233
237
 
234
- g.column :name => 'Title', :attribute => 'title' do |task|
238
+ g.column name: 'Title', attribute: 'title' do |task|
235
239
  task.title
236
240
  end
237
241
 
@@ -239,17 +243,17 @@ where the block contains just a call to the same attribute declared by :attribut
239
243
 
240
244
  <%= grid(@tasks_grid) do |g|
241
245
 
242
- g.column :name => 'ID', :attribute => 'id'
246
+ g.column name: 'ID', attribute: 'id'
243
247
 
244
- g.column :name => 'Title', :attribute => 'title'
248
+ g.column name: 'Title', attribute: 'title'
245
249
 
246
- g.column :name => 'Description', :attribute => 'description'
250
+ g.column name: 'Description', attribute: 'description'
247
251
 
248
- g.column :name => 'Archived', :attribute => 'archived' do |task|
252
+ g.column name: 'Archived', attribute: 'archived' do |task|
249
253
  task.archived? ? 'Yes' : 'No'
250
254
  end
251
255
 
252
- g.column do |task|
256
+ g.column do |task|
253
257
  link_to('Edit', edit_task_path(task))
254
258
  end
255
259
  end -%>
@@ -259,18 +263,18 @@ In this case +name+ will be used as the method name to send to the ActiveRecord
259
263
 
260
264
  If only ordering is needed, and no filter, we can turn off filters using <tt>:filter</tt> :
261
265
 
262
- g.column :name => 'ID', :attribute => 'id', :filter => false
266
+ g.column name: 'ID', attribute: 'id', filter: false
263
267
 
264
- If no ordering links are needed, use <tt>:ordering => false</tt>:
268
+ If no ordering links are needed, use <tt>ordering: false</tt>:
265
269
 
266
- g.column :name => 'Added', :attribute => 'created_at', :ordering => false
270
+ g.column name: 'Added', attribute: 'created_at', ordering: false
267
271
 
268
272
  It is important to understand that it is up to the developer to make sure that the value
269
273
  returned by a column block (the content of a cell) corresponds to the underlying database
270
274
  column specified by <tt>:attribute</tt> (and <tt>:model</tt> discussed below).
271
275
 
272
276
 
273
- === Rendering filter panel
277
+ == Rendering filter panel
274
278
 
275
279
  The filter panel can be shown and hidden clicking the icon with binoculars.
276
280
 
@@ -284,7 +288,7 @@ Possible values are:
284
288
 
285
289
  Example:
286
290
 
287
- <%= grid(@tasks_grid, :show_filters => :always) do |g|
291
+ <%= grid(@tasks_grid, show_filters: :always) do |g|
288
292
  ......
289
293
  end -%>
290
294
 
@@ -295,35 +299,35 @@ the icons in the additional column, set <tt>Wice::Defaults::REUSE_LAST_COLUMN_FO
295
299
  the configuration file.
296
300
 
297
301
 
298
- === Initial Ordering
302
+ == Initial Ordering
299
303
 
300
304
  Initializing the grid we can also define the column by which the record will be ordered
301
305
  <em>on the first rendering of the grid</em>, when the user has not set their ordering
302
306
  setting by clicking the column label, and the order direction:
303
307
 
304
308
  @tasks_grid = initialize_grid(Task,
305
- :order => 'tasks.title',
306
- :order_direction => 'desc'
309
+ order: 'tasks.title',
310
+ order_direction: 'desc'
307
311
  )
308
312
 
309
- === Records Per Page
313
+ == Records Per Page
310
314
 
311
315
  The number of rows per page is set with <tt>:per_page</tt>:
312
316
 
313
- @tasks_grid = initialize_grid(Task, :per_page => 40)
317
+ @tasks_grid = initialize_grid(Task, per_page: 40)
314
318
 
315
- === Conditions
319
+ == Conditions
316
320
 
317
321
  The +initialize_grid+ method supports a <tt>:conditions</tt> parameter which is passed
318
322
  on to the underlying ActiveRecord, so it can be in any format processable by ActiveRecord:
319
323
 
320
324
  @tasks_grid = initialize_grid(Task,
321
- :conditions => ["archived = false and estimated_time > ?", 100]
325
+ conditions: ["archived = false and estimated_time > ?", 100]
322
326
  )
323
327
 
324
328
  @tasks_grid = initialize_grid(Task,
325
- :include => :project,
326
- :conditions => {:archived => false, :project => {:active => true}}
329
+ include: :project,
330
+ conditions: {archived: false, project: {active: true}}
327
331
  )
328
332
 
329
333
 
@@ -334,14 +338,15 @@ A good example is substituting a common pattern like
334
338
 
335
339
  with WiceGrid code:
336
340
 
337
- @user_groups_grid = initialize_grid(UserGroup, :conditions => ['portal_application_id = ?', @portal_application])
341
+ @user_groups_grid = initialize_grid(
342
+ UserGroup,
343
+ conditions: ['portal_application_id = ?', @portal_application]
344
+ )
338
345
 
339
346
  Alternatively, instead of a Class object as the first parameter, you can use ActiveRecord::Relation:
340
347
 
341
-
342
- @tasks_grid = initialize_grid(Task.
343
- where(:archived => false, :projects => {:active => true}).
344
- joins(:project)
348
+ @tasks_grid = initialize_grid(
349
+ Task.where(archived: false, projects: {active: true}).joins(:project)
345
350
  )
346
351
 
347
352
 
@@ -349,19 +354,19 @@ Please note that though all queries inside of WiceGrid are run without the defau
349
354
  scope, if you use an ActiveRecord::Relation instance to initialize grid, it will
350
355
  already include the default scope. Thus you might consider using <tt>unscoped</tt>:
351
356
 
352
- @tasks_grid = initialize_grid(Task.unscoped.
353
- where(:archived => false, :projects => {:active => true}).
354
- joins(:project)
357
+ @tasks_grid = initialize_grid(
358
+ Task.unscoped.where(archived: false, projects: {active: true}).joins(:project)
355
359
  )
356
360
 
357
- === Queries with join tables
361
+ == Queries with join tables
358
362
 
359
363
  WiceGrid also supports ActiveRecord's <tt>:joins</tt> and <tt>:include</tt>.
360
364
 
361
365
  @products_grid = initialize_grid(Product,
362
- :include => :category,
363
- :order => 'products.name',
364
- :per_page => 20)
366
+ include: :category,
367
+ order: 'products.name',
368
+ per_page: 20
369
+ )
365
370
 
366
371
  Note that if we want to order initially by a column from a joined table we have to specify the
367
372
  table and the column name with the sql dot notation, that is, <tt>products.name</tt>
@@ -370,11 +375,11 @@ To show columns of joined tables in the view table, the ActiveRecord model class
370
375
  to be specified, that corresponds to the joined table:
371
376
 
372
377
  <%= grid(@products_grid) do |g|
373
- g.column :name => 'Product Name', :attribute => 'name' do |product| # primary table
378
+ g.column name: 'Product Name', attribute: 'name' do |product| # primary table
374
379
  link_to(product.name, product_path(product))
375
380
  end
376
381
 
377
- g.column :name => 'Category', :attribute => 'name', :model => Category |product| # joined table
382
+ g.column name: 'Category', attribute: 'name', model: Category do |product| # joined table
378
383
  product.category.name
379
384
  end
380
385
  %>
@@ -382,72 +387,69 @@ to be specified, that corresponds to the joined table:
382
387
  Please note that the blockless definition of the column only works with columns from the main table
383
388
  and it won't work with columns with <tt>:model</tt>
384
389
 
385
- === Joined associations referring to the same table
390
+ == Joined associations referring to the same table
386
391
 
387
- In case there are two joined associations both referring to the same table,
388
- ActiveRecord constructs a query where
389
- the second join provides an alias for the joined table. To enable WiceGrid to order and
390
- filter by columns belonging to different associations
391
- but originating from the same table, set <tt>:table_alias</tt> to this alias:
392
+ In case there are two joined associations both referring to the same table, ActiveRecord constructs
393
+ a query where the second join provides an alias for the joined table. To enable WiceGrid to order
394
+ and filter by columns belonging to different associations but originating from the same table, set
395
+ <tt>:table_alias</tt> to this alias:
392
396
 
393
397
  Model:
394
398
 
395
399
  class Project < ActiveRecord::Base
396
- belongs_to :customer, :class_name => 'Company'
397
- belongs_to :supplier, :class_name => 'Company'
400
+ belongs_to :customer, class_name: 'Company'
401
+ belongs_to :supplier, class_name: 'Company'
398
402
  end
399
403
 
400
404
  Controller:
401
405
 
402
- @projects_grid = initialize_grid(Project, :include => [:customer, :supplier] )
406
+ @projects_grid = initialize_grid(Project, include: [:customer, :supplier])
403
407
 
404
408
 
405
409
  View:
406
410
 
407
- <%= grid(@projects_grid, :show_filters => :always) do |g|
411
+ <%= grid(@projects_grid, show_filters: :always) do |g|
408
412
 
409
- g.column :name => 'Project Name', :attribute => 'name'
413
+ g.column name: 'Project Name', attribute: 'name'
410
414
 
411
- g.column :name => 'Customer company', :model => 'Company', :attribute => 'name' do |task|
415
+ g.column name: 'Customer company', model: 'Company', attribute: 'name' do |task|
412
416
  task.customer.name if task.customer
413
417
  end
414
418
 
415
- g.column :name => 'Supplier company', :model => 'Company', :attribute => 'name', :table_alias => ' suppliers_projects' do |task|
419
+ g.column name: 'Supplier company', model: 'Company', attribute: 'name', table_alias: 'suppliers_projects' do |task|
416
420
  task.supplier.name if task.supplier
417
421
  end
418
422
 
419
423
  end -%>
420
424
 
421
425
 
422
- === More than one grid on a page
426
+ == More than one grid on a page
423
427
 
424
- It is possible to use more that one grid on a page, each with its own state.
425
- To do so, you must specify the name of the grid in +initialize_grid+ using
426
- parameter <tt>:name</tt>
428
+ It is possible to use more that one grid on a page, each with its own state. To do so, you must
429
+ specify the name of the grid in +initialize_grid+ using parameter <tt>:name</tt>
427
430
 
428
- The name serves as the base name for HTTP parameters, DOM IDs, etc, so it
429
- is important that all grids on a page have different names. The default
430
- name is 'grid'.
431
+ The name serves as the base name for HTTP parameters, DOM IDs, etc, so it is important that all
432
+ grids on a page have different names. The default name is 'grid'.
431
433
 
432
434
  The name can only contain alphanumeric characters.
433
435
 
434
- @projects_grid = initialize_grid(Project, :name => 'g1' )
435
- @tasks_grid = initialize_grid(Task, :name => 'g2')
436
+ @projects_grid = initialize_grid(Project, name: 'g1')
437
+ @tasks_grid = initialize_grid(Task, name: 'g2')
436
438
 
437
439
 
438
- === Custom Ordering
440
+ == Custom Ordering
439
441
 
440
- It is possible to change the way results are ordered injecting a chunk of SQL code, for example, use
441
- <tt>ORDER BY INET_ATON(ip_address)</tt> instead of <tt>ORDER BY ip_address</tt>.
442
+ It is possible to change the way results are ordered injecting a chunk of SQL code,
443
+ for example, use <tt>ORDER BY INET_ATON(ip_address)</tt> instead of <tt>ORDER BY ip_address</tt>.
442
444
 
443
- To do so, provide parameter <tt>:custom_order</tt> in the initialization of the grid with a hash where keys are fully qualified names
444
- of database columns, and values the required chunks of SQL to use in the ORDER BY clause.
445
+ To do so, provide parameter <tt>:custom_order</tt> in the initialization of the grid with
446
+ a hash where keys are fully qualified names of database columns, and values the required chunks
447
+ of SQL to use in the ORDER BY clause.
445
448
 
446
449
  For example:
447
450
 
448
-
449
451
  @hosts_grid = initialize_grid(Host,
450
- :custom_order => {
452
+ custom_order: {
451
453
  'hosts.ip_address' => 'INET_ATON(hosts.ip_address)'
452
454
  })
453
455
 
@@ -455,23 +457,72 @@ For example:
455
457
  It is possible to use the '?' character instead of the name of the column in the hash value:
456
458
 
457
459
  @hosts_grid = initialize_grid(Host,
458
- :custom_order => {
460
+ custom_order: {
459
461
  'hosts.ip_address' => 'INET_ATON( ? )'
460
462
  })
461
463
 
462
464
  Values can also be Proc objects. The parameter supplied to such a Proc object is the name of the column:
463
465
 
464
466
  @hosts_grid = initialize_grid(Host,
465
- :custom_order => {
467
+ custom_order: {
466
468
  'hosts.ip_address' => lambda{|f| "INET_ATON( #{f} )"}
467
469
  })
468
470
 
471
+ == Filters
472
+
473
+ Each column filter type is supported by a <tt>column processor</tt>.
474
+ Each <tt>column processor</tt> is responsible for
475
+
476
+ * generating HTML and supporting Javascript for the filter, input fields, dropdowns, javascript calendars, etc
477
+ * converting HTTP parameters from those input fields into ActiveRelation instances
478
+
479
+ By default column filters depend on the type of the underlying database column.
480
+
481
+ You can override these defaults in two ways:
482
+
483
+ * defining a custom filter with <tt>:custom_filter</tt>. Read more about it section "Custom dropdown filters".
484
+ * overriding the <tt>column processor</tt> type with <tt>:filter_type</tt>.
485
+
486
+ Which Column Processor is instantiated for which data types is defined in file
487
+ <tt>lib/wice/columns/column_processor_index.rb</tt>:
488
+
489
+
490
+ module Wice
491
+ module Columns
492
+ COLUMN_PROCESSOR_INDEX = ActiveSupport::OrderedHash[
493
+ :action , 'column_action', # Special processor for action column, columns with checkboxes
494
+ :text , 'column_string',
495
+ :string , 'column_string',
496
+ :timestamp, 'column_datetime',
497
+ :datetime , 'column_datetime',
498
+ :date , 'column_date',
499
+ :integer , 'column_integer',
500
+ :range , 'column_range',
501
+ :float , 'column_float',
502
+ :decimal , 'column_float',
503
+ :custom , 'column_custom_dropdown', # Special processor for custom filter columns
504
+ :boolean , 'column_boolean'
505
+ ]
506
+ end
507
+ end
508
+
509
+ A good example for using <tt>:filter_type</tt> to change th default is numeric columns.
510
+ By default <tt>'column_integer'</tt> is instantiated for <tt>integer</tt> columns, and it
511
+ renders one input field. But it is also possible to use another Column Processor called
512
+ <tt>'column_range'</tt> which renders two input fields and searches for values in the given
513
+ the range instead of searching for values which equal the given search term.
514
+
515
+ It also possible to define and use your own column processors outside of the plugin, in
516
+ you application. Read more about this in section "Defining your own external filter processors".
517
+
469
518
 
470
519
  === Custom dropdown filters
471
520
 
472
- It is possible to construct custom dropdown filters.
473
- Depending on the value of <tt>column</tt> parameter<tt>:custom_filter</tt> different
474
- modes are available:
521
+ It is possible to construct custom dropdown filters. A custom dropdown filter
522
+ is essentially a dropdown list.
523
+
524
+ Depending on the value of
525
+ <tt>column</tt> parameter<tt>:custom_filter</tt> different modes are available:
475
526
 
476
527
 
477
528
  ==== Array of two-element arrays or a hash
@@ -482,32 +533,26 @@ Every first item of the two-element array is used for the label of the select op
482
533
  element is the value of the select option. In case of a hash the keys become the labels
483
534
  of the generated dropdown list, while the values will be values of options of the dropdown list:
484
535
 
485
- g.column :name => 'Status', :attribute => 'status',
486
- :custom_filter => {'Development' => 'development', 'Testing' => 'testing', 'Production' => 'production'}
536
+ g.column name: 'Status', attribute: 'status',
537
+ custom_filter: {'Development' => 'development', 'Testing' => 'testing', 'Production' => 'production'}
487
538
 
488
- g.column :name => 'Status', :attribute => 'status',
489
- :custom_filter => [['Development', 'development'], ['Testing', 'testing'], ['Production', 'production']]
539
+ g.column name: 'Status', attribute: 'status',
540
+ custom_filter: [['Development', 'development'], ['Testing', 'testing'], ['Production', 'production']]
490
541
 
491
542
  It is also possible to submit a array of strings or numbers, in this case every item will be used
492
543
  both as the value of the select option and as its label:
493
544
 
494
- g.column :name => 'Status', :attribute => 'status',
495
- :custom_filter => ['development', 'testing', 'production']
545
+ g.column name: 'Status', attribute: 'status', custom_filter: ['development', 'testing', 'production']
496
546
 
497
547
 
498
548
  ==== :auto
499
549
 
500
550
  <tt>:auto</tt> - a powerful option which populates the dropdown list with all unique values of
501
- the column specified by
502
- <tt>:attribute</tt> and <tt>:model</tt>.
551
+ the column specified by <tt>:attribute</tt> and <tt>:model</tt>, if present.
503
552
 
504
- g.column :name => 'Status', :attribute => 'status',
505
- :custom_filter => ['development', 'testing', 'production']
553
+ g.column name: 'Status', attribute: 'status', custom_filter: :auto
506
554
 
507
- Note that in the above example all names of all possible categories will appear even if they
508
- don't appear in the current resultset.
509
- To only show those which do appear in the resutset,
510
- use an array of symbol messages (see section 'An array of symbols').
555
+ In the above example all statuses will appear in the dropdown even if they don't appear in the current resultset.
511
556
 
512
557
 
513
558
  ==== Custom filters and associations (joined tables)
@@ -518,26 +563,26 @@ To correctly build a filter condition foreign keys have to be used, not the actu
518
563
 
519
564
  For example, if there is a column:
520
565
 
521
- g.column :name => 'Project Name', :attribute => 'name', :model => 'Project' do |task|
566
+ g.column name: 'Project Name', attribute: 'name', model: 'Project' do |task|
522
567
  task.project.name if task.project
523
568
  end
524
569
 
525
570
  adding <tt>:custom_filter</tt> like this:
526
571
 
527
- g.column :name => 'Project Name', :attribute => 'name', :model => 'Project',
528
- :custom_filter => Project.find(:all).map{|pr| [pr.name, pr.name]} do |task|
572
+ g.column name: 'Project Name', attribute: 'name', model: 'Project',
573
+ custom_filter: Project.find(:all).map{|pr| [pr.name, pr.name]} do |task|
529
574
  task.project.name if task.project
530
575
  end
531
576
 
532
577
  is bad style and can fail, because the resulting condition will compare the name of the project, <tt>projects.name</tt> to a string,
533
578
  and in some databases it is possible that different records (projects in our example) have the same name.
534
579
 
535
- To use filter with foreign keys, we have to change the declaration of the column from <tt>projects.name</tt>, to
580
+ To use filter with foreign keys, it is advised to change the declaration of the column from <tt>projects.name</tt>, to
536
581
  <tt>tasks.project_id</tt>, and build the dropdown with foreign keys as values:
537
582
 
538
583
 
539
- g.column :name => 'Project Name', :attribute => 'tasks.project_id',
540
- :custom_filter => Project.find(:all).map{|pr| [pr.id, pr.name]} do |task|
584
+ g.column name: 'Project Name', attribute: 'tasks.project_id',
585
+ custom_filter: Project.find(:all).map{|pr| [pr.id, pr.name]} do |task|
541
586
  task.project.name if task.project
542
587
  end
543
588
 
@@ -545,8 +590,8 @@ However, this will break the ordering of the column - the column will be ordered
545
590
  To fix this, we can override the ordering using <tt>:custom_order</tt>:
546
591
 
547
592
  @tasks_grid = initialize_grid(Task,
548
- :include => :project,
549
- :custom_order => {
593
+ include: :project,
594
+ custom_order: {
550
595
  'tasks.project_id' => 'projects.name'
551
596
  }
552
597
  )
@@ -555,9 +600,8 @@ To fix this, we can override the ordering using <tt>:custom_order</tt>:
555
600
  ==== Any other symbol (method name) or an array of symbols (method names)
556
601
 
557
602
 
558
- For one symbol (different from <tt>:auto</tt>) the dropdown list is populated by all
559
- unique values returned by the method with this name
560
- sent to <em>all</em> ActiveRecord objects throughout all pages.
603
+ For one symbol (different from <tt>:auto</tt>) the dropdown list is populated by all unique values
604
+ returned by the method with this name sent to <em>all</em> ActiveRecord objects throughout all pages.
561
605
 
562
606
  The conditions set up by the user are ignored, that is, the records used are all those found on
563
607
  all pages without any filters active.
@@ -567,7 +611,7 @@ object if it responds to this method, the second method name is sent to the
567
611
  returned value unless it is +nil+, and so on. In other words, a single symbol mode is the
568
612
  same as an array of symbols where the array contains just one element.
569
613
 
570
- g.column :name => 'Version', :attribute => 'expected_version_id', :custom_filter => [:expected_version, :to_option] do |task|
614
+ g.column name: 'Version', attribute: 'expected_version_id', custom_filter: [:expected_version, :to_option] do |task|
571
615
  task.expected_version.name if task.expected_version
572
616
  end
573
617
 
@@ -599,7 +643,7 @@ Typically, a model method like the following:
599
643
 
600
644
  together with
601
645
 
602
- :custom_filter => :to_option
646
+ custom_filter: :to_option
603
647
 
604
648
  would do the trick:
605
649
 
@@ -615,8 +659,7 @@ and the key - for the value:
615
659
 
616
660
  ==== Special treatment of values 'null' and 'not null'
617
661
 
618
- Values 'null' and 'not null' in a generated custom filter are treated specially,
619
- as SQL +null+ statement and not as strings.
662
+ Values 'null' and 'not null' in a generated custom filter are treated specially, as SQL +null+ statement and not as strings.
620
663
  Value 'null' is transformed into SQL condition <tt>IS NULL</tt>, and 'not null' into <tt>IS NOT NULL</tt>
621
664
 
622
665
  Thus, if in a filter defined by
@@ -632,28 +675,173 @@ By default it is possible for any dropdown list to switch between single and mul
632
675
  To only allow single selection use <tt>:allow_multiple_selection</tt>:
633
676
 
634
677
 
635
- g.column :name => 'Expected in version', :attribute => 'expected_version_id',
636
- :custom_filter => [:expected_version, :to_option], :allow_multiple_selection => false do |task|
678
+ g.column name: 'Expected in version', attribute: 'expected_version_id',
679
+ custom_filter: [:expected_version, :to_option], allow_multiple_selection: false do |task|
637
680
  ...
638
681
  end
639
682
 
640
683
 
641
- ==== Numeric Filters
684
+ === Numeric Filters
642
685
 
643
686
  Before version 3.2.1 the filter used for numeric columns was a range filter with two limits. Beginning with version 3.2.1
644
687
  the default is a direct comparison filter with one input field. The old range filter can still be loaded using parameter <tt>:filter_type</tt>
645
688
  with value <tt>:range</tt>:
646
689
 
647
- g.column :filter_type => :range do |task|
690
+ g.column filter_type: :range do |task|
648
691
  ...
649
692
  end
650
693
 
651
694
 
652
- === Defaults
695
+ === Javascript Calendar for Date and DateTime Filters.
696
+
697
+ WiceGrid uses jQuery datepicker[http://jqueryui.com/demos/datepicker/] for Date and DateTime filters by default.
698
+ Because this is part of the standard jQuery codebase, it is not bundled together with the plugin,
699
+ and it is the responsibility of the programmer to include all necessary assets including
700
+ localization files if the application is multilingual.
701
+
702
+
703
+ jQuery datepicker does not have any time related controls, and when dealing with DateTime filters, the time value is ignored.
704
+
705
+ Another option is standard Rails helpers. It's possible to change between the two styles of Date/DateTime
706
+ filters in <tt>config/initializers/wice_grid_config.rb</tt> using constant HELPER_STYLE, or set it on per-column basis:
707
+
708
+ g.column name: 'Due Date', attribute: 'due_date', helper_style: :calendar do |task|
709
+ task.due_date.to_s(:short) if task.due_date
710
+ end
711
+
712
+ g.column name: 'Updated', attribute: 'updated_at', helper_style: :standard do |task|
713
+ task.created_at.to_s(:short)
714
+ end
715
+
716
+ Constants +DATE_FORMAT+ and +DATETIME_FORMAT+ in the configuration file define the format of dates the user will see, as well as the
717
+ format of the string sent in a HTTP parameter. If you change the formats, make sure that lamdbas defined
718
+ in +DATETIME_PARSER+ and +DATE_PARSER+ return valid DateTime and Date objects.
719
+
720
+ jQuery +datepicker+ uses a different format flavor, therefore there is an additional constant
721
+ +DATE_FORMAT_JQUERY+. While +DATE_FORMAT_JQUERY+ is fed to +datepicker+, +DATE_FORMAT+ is still used
722
+ for presenting initial date values in filters, so make sure that +DATE_FORMAT_JQUERY+ and +DATE_FORMAT+
723
+ result in an identical date representation.
724
+
725
+ Constant +DATEPICKER_YEAR_RANGE+ defined the range of years in the Datepicker year dropdown. Alternatively,
726
+ you can always change this range dynamically with the following javascript:
727
+
728
+ $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" );
729
+
730
+
731
+
732
+ == Detached Filters
733
+
734
+ Filters can also be detached from the grid table and placed anywhere on page.
735
+
736
+ This is a 3-step process.
737
+
738
+ First, define the grid with helper +define_grid+ instead of +grid+.
739
+ Everything should be done the same way as with +grid+, but every column which will have an external filter,
740
+ add <tt>detach_with_id: :some_filter_name+</tt> in the column definition. The value of +:detach_with_id+ is an arbitrary string
741
+ or a symbol value which will be used later to identify the filter.
742
+
743
+ <%= define_grid(@tasks_grid, show_filters: :always) do |g|
744
+
745
+ g.column name: 'Title', attribute: 'title', detach_with_id: :title_filter do |task|
746
+ link_to('Edit', edit_task_path(task.title))
747
+ end
748
+
749
+ g.column name: 'Archived', attribute: 'archived', detach_with_id: :archived_filter do |task|
750
+ task.archived? ? 'Yes' : 'No'
751
+ end
752
+
753
+ g.column name: 'Added', attribute: 'created_at', detach_with_id: :created_at_filter do |task|
754
+ task.created_at.to_s(:short)
755
+ end
756
+
757
+ end -%>
758
+
759
+
760
+ Then, use <tt>grid_filter(grid, :some_filter_name)</tt> to render filters:
761
+
762
+ <% # rendering filter with key :title_filter %>
763
+ <%= grid_filter @tasks_grid, :title_filter %>
764
+
765
+ <% # rendering filter with key :archived_filter %>
766
+ <%= grid_filter @tasks_grid, :archived_filter %>
767
+
768
+ <% # rendering filter with key :created_at_filter %>
769
+ <%= grid_filter @tasks_grid, :created_at_filter %>
770
+
771
+ <% # Rendering the grid body %>
772
+ <%= grid(@tasks_grid) %>
773
+
774
+
775
+ Finally, use <tt>render_grid(@grid)</tt> to actually output the grid table .
776
+
777
+
778
+ Using custom submit and reset buttons together with <tt>:hide_submit_button => true</tt>
779
+ and <tt>:hide_reset_button => true</tt> allows to completely get rid
780
+ of the default filter row and the default icons (see section 'Submit/Reset Buttons').
781
+
782
+
783
+ If a column was declared with <tt>:detach_with_id</tt>, but never output with +grid_filter+,
784
+ filtering the grid in development mode will result in an warning javascript message and the missing filter will be ignored.
785
+ There is no such message in production.
786
+
787
+
788
+ === Defining your own external filter processors
789
+
790
+
791
+ It possible to define and use your own column processors outside of the plugin, in
792
+ you application.
793
+
794
+ The first step is to edit <tt>Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS</tt> in
795
+ <tt>wice_grid_config.rb</tt>:
796
+
797
+
798
+ Wice::Defaults::ADDITIONAL_COLUMN_PROCESSORS = {
799
+ my_own_filter: ['ViewColumnMyOwnFilter', 'ConditionsGeneratorMyOwnFilter'],
800
+ another_filter: ['ViewColumnAnotherFilter', 'ConditionsGeneratorAnotherFilter']
801
+ }
802
+
803
+ The first element in the two-item array is the name of a class responsible for rendering
804
+ the filter view. The second element is the name of a class responsible for processing
805
+ filter parameters.
806
+
807
+ For examples of these two classes look at the existing column processors in <tt>lib/wice/columns/</tt>
808
+
809
+ The structure of these two classes is as follows:
810
+
811
+ class ViewColumnMyOwnFilter < Wice::Columns::ViewColumn
812
+
813
+ def render_filter_internal(params)
814
+ ...
815
+ end
816
+
817
+ def yield_declaration_of_column_filter
818
+ {
819
+ :templates => [...],
820
+ :ids => [...]
821
+ }
822
+ end
823
+ end
824
+
825
+
826
+ class ConditionsGeneratorMyOwnFilter < Wice::Columns::ConditionsGeneratorColumn
827
+
828
+ def generate_conditions(table_name, opts)
829
+ ...
830
+ end
831
+
832
+ end
833
+
834
+ To use an external column processor use <tt>:filter_type</tt> in a column definition:
835
+
836
+ column name: 'name', attribute: 'attribute', filter_type: :my_own_filter do |rec|
837
+ ...
838
+ end
839
+
840
+ == Defaults
653
841
 
654
842
  Default values like can be changed in <tt>config/initializers/wice_grid_config.rb</tt>.
655
843
 
656
- === Submit/Reset buttons
844
+ == Submit/Reset buttons
657
845
  Instead of using default Submit and Reset icons you can use external HTML elements to trigger
658
846
  these actions. Add a button or any other clickable HTML element with class
659
847
  +wg-external-submit-button+ or +wg-external-reset-button+, and attribute +data-grid-name+
@@ -668,7 +856,7 @@ To hide the default icons use <tt>:hide_submit_button => true</tt> and
668
856
 
669
857
 
670
858
 
671
- === Auto-reloading filters
859
+ == Auto-reloading filters
672
860
 
673
861
  It is possible to configure a grid to reload itself once a filter has been changed. It works with all
674
862
  filter types including the JS calendar, the only exception is the standard Rails date/datetime filters.
@@ -676,21 +864,21 @@ filter types including the JS calendar, the only exception is the standard Rails
676
864
  Use option <tt>:auto_reload</tt> in the column definiton:
677
865
 
678
866
 
679
- <%= grid(@tasks_grid, :show_filters => :always, :hide_submit_button => true) do |g|
867
+ <%= grid(@tasks_grid, show_filters: :always, hide_submit_button: true) do |g|
680
868
 
681
869
  # String
682
- g.column :name => 'Title', :attribute => 'title', :auto_reload => true
870
+ g.column name: 'Title', attribute: 'title', auto_reload: true
683
871
 
684
872
  # Boolean
685
- g.column :name => 'Archived', :attribute => 'archived', :auto_reload => true
873
+ g.column name: 'Archived', attribute: 'archived', auto_reload: true
686
874
 
687
875
  # Custom (dropdown)
688
- g.column :name => 'Status', :attribute => 'status_id', :custom_filter => Status.to_dropdown, :auto_reload => true do |task|
876
+ g.column name: 'Status', attribute: 'status_id', custom_filter: Status.to_dropdown, auto_reload: true do |task|
689
877
  task.status.name if task.status
690
878
  end
691
879
 
692
880
  # Datetime
693
- g.column :name => 'Added', :attribute => 'created_at', :auto_reload => true, :helper_style => :calendar do |task|
881
+ g.column name: 'Added', attribute: 'created_at', auto_reload: true, helper_style: :calendar do |task|
694
882
  task.created_at.to_s(:short)
695
883
  end
696
884
 
@@ -698,23 +886,21 @@ Use option <tt>:auto_reload</tt> in the column definiton:
698
886
 
699
887
  To make this behavior default change constant +AUTO_RELOAD+ in the configuration file.
700
888
 
701
- === Styling the grid
889
+ == Styling the grid
702
890
 
703
891
 
704
- ==== Adding classes and styles
892
+ === Adding classes and styles
705
893
 
706
- The +grid+ helper accepts parameter <tt>:html</tt> which is a hash of HTML
707
- attributes for the table tag.
894
+ The +grid+ helper accepts parameter <tt>:html</tt> which is a hash of HTML attributes for the table tag.
708
895
 
709
896
  Another +grid+ parameter is <tt>header_tr_html</tt> which is a hash of HTML attributes to
710
897
  be added to the first +tr+ tag (or two first +tr+'s if the filter row is present).
711
898
 
712
899
  <tt>:html</tt> is a parameter for the +column+ method setting HTML attributes of +td+ tags for a certain column.
713
900
 
714
- ==== Adding classes and styles dynamically
901
+ === Adding classes and styles dynamically
715
902
 
716
- WiceGrid offers ways to dynamically add classes and styles to +TR+ and +TD+
717
- based on the current ActiveRecord instance.
903
+ WiceGrid offers ways to dynamically add classes and styles to +TR+ and +TD+ based on the current ActiveRecord instance.
718
904
 
719
905
 
720
906
  For <tt><TD></tt>, let the +column+ return an array where the first item is the usual
@@ -745,7 +931,7 @@ Naturally, there can be only one +row_attributes+ definition for a WiceGrid inst
745
931
  Various classes do not overwrite each other, instead, they are concatenated.
746
932
 
747
933
 
748
- === Adding rows to the grid
934
+ == Adding rows to the grid
749
935
 
750
936
  It is possible to add your own handcrafted HTML after and/or before each grid row.
751
937
  This works similar to +row_attributes+, by adding blocks +after_row+, +before_row+, and +last_row+:
@@ -771,15 +957,13 @@ This works similar to +row_attributes+, by adding blocks +after_row+, +before_ro
771
957
  .......
772
958
  end %>
773
959
 
774
- It is up for the developer to return the correct HTML code, or
775
- return +nil+ if no row is needed for this record.
776
- Naturally, there is only one +before_row+ definition and one +after_row+
777
- definition for a WiceGrid instance.
960
+ It is up for the developer to return the correct HTML code, or return +nil+ if no row is needed for this record.
961
+ Naturally, there is only one +before_row+ definition and one +after_row+ definition for a WiceGrid instance.
778
962
 
779
963
  The second variable injected into to <tt>before_row</tt> and <tt>after_row</tt> block, and the first parameter injected
780
964
  into the <tt>last_row</tt> is the number of columns in the current grid.
781
965
 
782
- === Rendering a grid without records
966
+ == Rendering a grid without records
783
967
 
784
968
  If the grid does not contain any records to show, it is possible show some alternative view instead of
785
969
  an empty grid. Bear in mind that if the user sets up the filters in such a way that the selection of
@@ -806,7 +990,7 @@ Or a partial:
806
990
  g.blank_slate :partial => "partial_name"
807
991
 
808
992
 
809
- === Action Column
993
+ == Action Column
810
994
 
811
995
  It is possible to add a column with checkboxes for each record. This is useful for actions with multiple records,
812
996
  for example, deleting selected records. Please note that +action_column+ only creates the checkboxes and the
@@ -848,18 +1032,16 @@ WiceGrid is form-friendly: submitting grid in a form retains the state of the fo
848
1032
 
849
1033
 
850
1034
 
851
- === Integration of the grid with other forms on page
1035
+ == Integration of the grid with other forms on page
852
1036
 
853
1037
  Imagine that the user should be able to change the behavior of the grid using some other control
854
1038
  on the page, and not a grid filter.
855
1039
 
856
- For example, on a page showing tasks,
857
- change between 'Show active tasks' to 'Show archived tasks' using a dropdown box.
858
- WiceGrid allows to keep the status of the grid with all the filtering and sorting
859
- using helper +dump_filter_parameters_as_hidden_fields+ which takes a grid object and dumps
860
- all current sorting and filtering parameters as
861
- hidden fields. Just include <tt>dump_filter_parameters_as_hidden_fields(@grid)</tt> inside your form,
862
- and the newly rendered grid will keep ordering and filtering.
1040
+ For example, on a page showing tasks, change between 'Show active tasks' to 'Show archived tasks' using a dropdown box.
1041
+ WiceGrid allows to keep the status of the grid with all the filtering and sorting using helper
1042
+ +dump_filter_parameters_as_hidden_fields+ which takes a grid object and dumps
1043
+ all current sorting and filtering parameters as hidden fields. Just include
1044
+ <tt>dump_filter_parameters_as_hidden_fields(@grid)</tt> inside your form, and the newly rendered grid will keep ordering and filtering.
863
1045
 
864
1046
  <% form_tag('', :method => :get) do %>
865
1047
  <%= dump_filter_parameters_as_hidden_fields(@tasks_grid) %>
@@ -869,45 +1051,8 @@ and the newly rendered grid will keep ordering and filtering.
869
1051
  <% end -%>
870
1052
 
871
1053
 
872
- === Javascript Calendar for Date and DateTime Filters.
873
1054
 
874
- WiceGrid uses jQuery datepicker[http://jqueryui.com/demos/datepicker/] for Date and DateTime filters
875
- by default.
876
- Because this is part of the standard jQuery codebase, it is not bundled together with the plugin,
877
- and it is the responsibility of the programmer to include all necessary assets including
878
- localization files if the application is multilingual.
879
-
880
-
881
- jQuery datepicker does not have any time related controls, and when dealing with DateTime filters,
882
- the time value is ignored.
883
-
884
- Another option is standard Rails helpers. It's possible to change between the two styles of Date/DateTime
885
- filters in <tt>config/initializers/wice_grid_config.rb</tt> using constant HELPER_STYLE, or set it on per-column basis:
886
-
887
- g.column :name => 'Due Date', :attribute => 'due_date', :helper_style => :calendar do |task|
888
- task.due_date.to_s(:short) if task.due_date
889
- end
890
-
891
- g.column :name => 'Updated', :attribute => 'updated_at', :helper_style => :standard do |task|
892
- task.created_at.to_s(:short)
893
- end
894
-
895
- Constants +DATE_FORMAT+ and +DATETIME_FORMAT+ in the configuration file define the format of dates the user will see, as well as the
896
- format of the string sent in a HTTP parameter. If you change the formats, make sure that lamdbas defined
897
- in +DATETIME_PARSER+ and +DATE_PARSER+ return valid DateTime and Date objects.
898
-
899
- jQuery +datepicker+ uses a different format flavor, therefore there is an additional constant
900
- +DATE_FORMAT_JQUERY+. While +DATE_FORMAT_JQUERY+ is fed to +datepicker+, +DATE_FORMAT+ is still used
901
- for presenting initial date values in filters, so make sure that +DATE_FORMAT_JQUERY+ and +DATE_FORMAT+
902
- result in an identical date representation.
903
-
904
- Constant +DATEPICKER_YEAR_RANGE+ defined the range of years in the Datepicker year dropdown. Alternatively,
905
- you can always change this range dynamically with the following javascript:
906
-
907
- $( ".hasDatepicker" ).datepicker( "option", "yearRange", "2000:2042" );
908
-
909
-
910
- === Show All Records
1055
+ == Show All Records
911
1056
 
912
1057
  It is possible to switch to the All Records mode clicking on link "show all" in the bottom right corner.
913
1058
  This functionality should be used with care. To turn this mode off for all grid instances,
@@ -918,7 +1063,7 @@ Configuration constant +START_SHOWING_WARNING_FROM+ sets the threshold number of
918
1063
  which clicking on the link results in a javascript confirmation dialog.
919
1064
 
920
1065
 
921
- === CSV Export
1066
+ == CSV Export
922
1067
 
923
1068
  It is possible to export the data displayed on a grid to a CSV file. The dumped data is the current resultset
924
1069
  with all the current filters and sorting applied, only without the pagination constraint (i.e. all pages).
@@ -926,10 +1071,10 @@ with all the current filters and sorting applied, only without the pagination co
926
1071
  To enable CSV export add parameters +enable_export_to_csv+ and +csv_file_name+ to the initialization of the grid:
927
1072
 
928
1073
  @projects_grid = initialize_grid(Project,
929
- :include => [:customer, :supplier],
930
- :name => 'g2',
931
- :enable_export_to_csv => true,
932
- :csv_file_name => 'projects'
1074
+ include: [:customer, :supplier],
1075
+ name: 'g2',
1076
+ enable_export_to_csv: true,
1077
+ csv_file_name: 'projects'
933
1078
  )
934
1079
 
935
1080
  +csv_file_name+ is the name of the downloaded file. This parameter is optional, if it is missing, the name of
@@ -967,15 +1112,15 @@ as the last line of the action:
967
1112
  def index
968
1113
 
969
1114
  @tasks_grid = initialize_grid(Task,
970
- :name => 'g1',
971
- :enable_export_to_csv => true,
972
- :csv_file_name => 'tasks'
1115
+ name: 'g1',
1116
+ enable_export_to_csv: true,
1117
+ csv_file_name: 'tasks'
973
1118
  )
974
1119
 
975
1120
  @projects_grid = initialize_grid(Project,
976
- :name => 'g2',
977
- :enable_export_to_csv => true,
978
- :csv_file_name => 'projects'
1121
+ name: 'g2',
1122
+ enable_export_to_csv: true,
1123
+ csv_file_name: 'projects'
979
1124
  )
980
1125
 
981
1126
  export_grid_if_requested
@@ -989,7 +1134,7 @@ Otherwise, to avoid double rendering, use the return value of the method to cond
989
1134
 
990
1135
  ...........
991
1136
 
992
- export_grid_if_requested || render(:action => 'my_template')
1137
+ export_grid_if_requested || render(action: 'my_template')
993
1138
  end
994
1139
 
995
1140
 
@@ -1000,7 +1145,7 @@ It's also possible to supply a block which will be called if no CSV export is re
1000
1145
  ...........
1001
1146
 
1002
1147
  export_grid_if_requested do
1003
- render(:action => 'my_template')
1148
+ render(action: 'my_template')
1004
1149
  end
1005
1150
  end
1006
1151
 
@@ -1008,105 +1153,45 @@ It's also possible to supply a block which will be called if no CSV export is re
1008
1153
  If a column has to be excluded from the CSV export,
1009
1154
  set +column+ parameter +in_csv+ to +false+:
1010
1155
 
1011
- g.column :in_csv => false do |task|
1156
+ g.column in_csv: false do |task|
1012
1157
  link_to('Edit', edit_task_path(task))
1013
1158
  end
1014
1159
 
1015
- If a column must appear both in HTML and CSV, but with different output,
1016
- duplicate the column and use
1160
+ If a column must appear both in HTML and CSV, but with different output, duplicate the column and use
1017
1161
  parameters +in_csv+ and +in_html+ to include one of them to html output only, the other to CSV only:
1018
1162
 
1019
1163
 
1020
1164
  # html version
1021
- g.column :name => 'Title', :attribute => 'title', :in_csv => false do |task|
1165
+ g.column name: 'Title', attribute: 'title', in_csv: false do |task|
1022
1166
  link_to('Edit', edit_task_path(task.title))
1023
1167
  end
1024
1168
  # plain text version
1025
- g.column :name => 'Title', :in_html => false do |task|
1169
+ g.column name: 'Title', in_html: false do |task|
1026
1170
  task.title
1027
1171
  end
1028
1172
 
1029
1173
  The default field separator in generated CSV is a comma, but it's possible to override it:
1030
1174
 
1031
1175
  @products_grid = initialize_grid(Product,
1032
- :enable_export_to_csv => true,
1033
- :csv_field_separator => ';',
1034
- :csv_file_name => 'products')
1176
+ enable_export_to_csv: true,
1177
+ csv_field_separator: ';',
1178
+ csv_file_name: 'products'
1179
+ )
1035
1180
 
1036
1181
  If you need an external CSV export button , add class +wg-external-csv-export-button+
1037
- to any clickable element on page and set its attribute +data-grid-name+ to the name of
1038
- the grid:
1182
+ to any clickable element on page and set its attribute +data-grid-name+ to the name of the grid:
1039
1183
 
1040
1184
  <button class="wg-external-csv-export-button" data-grid-name="grid">Export To CSV</button>
1041
1185
 
1042
- If you need to disable the default export icon in the grid, add
1043
- <tt>:hide_csv_button => true</tt> to the +grid+ helper.
1044
-
1045
- === Detached Filters
1046
-
1047
- Filters can also be detached from the grid table and placed anywhere on page.
1048
-
1049
- This is a 3-step process.
1050
-
1051
- First, define the grid with helper +define_grid+ instead of +grid+.
1052
- Everything should be done the same way as with +grid+, but every column which will have an external filter,
1053
- add <tt>:detach_with_id => :some_filter_name+</tt> in the column definition. The value of +:detach_with_id+ is an arbitrary string
1054
- or a symbol value which will be used later to identify the filter.
1055
-
1056
- <%= define_grid(@tasks_grid, :show_filters => :always) do |g|
1057
-
1058
- g.column :name => 'Title', :attribute => 'title', :detach_with_id => :title_filter do |task|
1059
- link_to('Edit', edit_task_path(task.title))
1060
- end
1061
-
1062
- g.column :name => 'Archived', :attribute => 'archived', :detach_with_id => :archived_filter do |task|
1063
- task.archived? ? 'Yes' : 'No'
1064
- end
1065
-
1066
- g.column :name => 'Added', :attribute => 'created_at', :detach_with_id => :created_at_filter do |task|
1067
- task.created_at.to_s(:short)
1068
- end
1069
-
1070
- end -%>
1071
-
1072
-
1073
- Then, use <tt>grid_filter(grid, :some_filter_name)</tt> to render filters:
1074
-
1075
- <% # rendering filter with key :title_filter %>
1076
- <%= grid_filter @tasks_grid, :title_filter %>
1077
-
1078
- <% # rendering filter with key :archived_filter %>
1079
- <%= grid_filter @tasks_grid, :archived_filter %>
1186
+ If you need to disable the default export icon in the grid, add <tt>hide_csv_button: true</tt> to the +grid+ helper.
1080
1187
 
1081
- <% # rendering filter with key :created_at_filter %>
1082
- <%= grid_filter @tasks_grid, :created_at_filter %>
1083
1188
 
1084
- <% # Rendering the grid body %>
1085
- <%= grid(@tasks_grid) %>
1086
-
1087
-
1088
- Finally, use <tt>render_grid(@grid)</tt> to actually output the grid table .
1089
-
1090
-
1091
- Using custom submit and reset buttons together with <tt>:hide_submit_button => true</tt>
1092
- and <tt>:hide_reset_button => true</tt>
1093
- allows to completely get rid
1094
- of the default filter row and the default icons (see section 'Submit/Reset Buttons').
1095
-
1096
-
1097
- If a column was declared with <tt>:detach_with_id</tt>, but never output with +grid_filter+,
1098
- filtering the grid in development mode will result
1099
- in an warning javascript message and the missing filter will be ignored.
1100
- There is no such message in production.
1101
-
1102
-
1103
-
1104
- === Access to Records From Outside The Grid
1189
+ == Access to Records From Outside The Grid
1105
1190
 
1106
1191
  There are two ways you can access the records outside the grid - using methods of the WiceGrid
1107
1192
  object and using callbacks.
1108
1193
 
1109
- ==== Accessing Records Via The WiceGrid Object
1194
+ === Accessing Records Via The WiceGrid Object
1110
1195
 
1111
1196
  Method +current_page_records+ returns exactly the same list of objects displayed on page:
1112
1197
 
@@ -1139,7 +1224,7 @@ This is due to the lazy nature of WiceGrid - the actual call to the database is
1139
1224
  the execution of
1140
1225
  the +grid+ helper, because to build the correct query columns declarations are required.
1141
1226
 
1142
- ==== Accessing Records Via Callbacks
1227
+ === Accessing Records Via Callbacks
1143
1228
 
1144
1229
  It is possible to set up callbacks which are executed from within the plugin just after the call to the database.
1145
1230
  The callbacks are called before rendering the grid cells, so the results of this processing can be used in the grid.
@@ -1149,9 +1234,9 @@ Via a lambda object:
1149
1234
 
1150
1235
  def index
1151
1236
  @tasks_grid = initialize_grid(Task,
1152
- :with_paginated_resultset => lambda do |records|
1237
+ with_paginated_resultset: ->(records){
1153
1238
  ...
1154
- end
1239
+ }
1155
1240
  )
1156
1241
  end
1157
1242
 
@@ -1159,7 +1244,7 @@ Via a symbol which is the name of a controller method:
1159
1244
 
1160
1245
  def index
1161
1246
  @tasks_grid = initialize_grid(Task,
1162
- :with_paginated_resultset => :process_selection
1247
+ with_paginated_resultset: :process_selection
1163
1248
  )
1164
1249
  end
1165
1250
 
@@ -1190,7 +1275,7 @@ receives an ActiveRelation object which can be used to obtain the list of all re
1190
1275
  @tasks_grid = initialize_grid(Task)
1191
1276
 
1192
1277
  @tasks_grid.with_resultset do |active_relation|
1193
- all_records = active_relation.find(:first)
1278
+ all_records = active_relation.all
1194
1279
  ...
1195
1280
  end
1196
1281
  end
@@ -1203,9 +1288,9 @@ only under certain circumstances:
1203
1288
  def index
1204
1289
  @tasks_grid = initialize_grid(Task)
1205
1290
 
1206
- @tasks_grid.with_resultset do |wrapper|
1291
+ @tasks_grid.with_resultset do |active_relation|
1207
1292
  if params[:process_all_records]
1208
- all_records = wrapper.call
1293
+ all_records = active_relation.all
1209
1294
  ...
1210
1295
  end
1211
1296
  end