You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"SUM((order_items.price * order_items.quantity) + (CASE order_items.tax_exempt WHEN true THEN 0 ELSE ((order_items.price * order_items.quantity) * order_items.tax_rate) END))"
192
201
end
193
202
```
194
203
@@ -251,6 +260,7 @@ The following options control the display behaviour of the column:
251
260
:sortable => true|false# Allow sorting of this column. Otherwise the up/down arrows on the frontend will be disabled.
252
261
:visible => true|false# Hide this column at startup. Column visbility can be changed on the frontend. By default, hidden column filter terms are ignored.
253
262
:width => '100%'|'100px'# Set the width of this column. Can be set on one, all or some of the columns. If using percentages, should never add upto more than 100%
263
+
:class => 'col-example'# Adds an html class to the column's TH and all TD elements. Add more than one class with 'example col-example something'
254
264
```
255
265
256
266
### Filtering Options
@@ -374,10 +384,84 @@ Sort the table by this field and direction on start up
374
384
default_order :created_at, :asc|:desc
375
385
```
376
386
387
+
## default_entries
388
+
389
+
The number of entries to show per page
390
+
391
+
```ruby
392
+
default_entries :all
393
+
```
394
+
395
+
Valid options are `10, 25, 50, 100, 250, 1000, :all`
396
+
397
+
377
398
## Additional Functionality
378
399
379
400
There are a few other ways to customize the behaviour of effective_datatables
380
401
402
+
### Display of an Empty Datatable
403
+
404
+
How an empty datatable (0 display records) is displayed depends on how `render_datatable` is called.
405
+
406
+
To render the full datatable with the default 'No data available in table' message:
407
+
408
+
```haml
409
+
= render_datatable(@datatable)
410
+
```
411
+
412
+
To skip rendering the datatable and just output a custom message:
413
+
414
+
```haml
415
+
= render_datatable(@datatable, 'There are no posts.')
416
+
```
417
+
418
+
or
419
+
420
+
```haml
421
+
= render_datatable(@datatable, :empty => 'There are no posts.')
422
+
```
423
+
424
+
To skip rendering the datatable and instead render given content:
425
+
426
+
```haml
427
+
= render_datatable(@datatable) do
428
+
%p There are no posts.
429
+
%p
430
+
Have a picture of a cat instead
431
+
= image_tag('cat.png')
432
+
```
433
+
434
+
### Checking for Empty collection
435
+
436
+
While the 'what to render when empty' situation is handled by the above syntax, you may still check whether the datatable has records to display by calling `@datatable.empty?` and `@datatable.present?`.
437
+
438
+
The gotcha with these methods is that the `@datatable.view` must first be assigned (which is done automatically by the `render_datatable` view method).
439
+
440
+
This implementation is a bit awkward but has significant performance tradeoffs.
441
+
442
+
To check for an empty datatable collection before it's rendered, you must manually assign a view:
443
+
444
+
```ruby
445
+
classPostsController < ApplicationController
446
+
defindex
447
+
@datatable=Effective::Datatables::Posts.new()
448
+
@datatable.view = view_context # built in Rails controller method refering to the view
449
+
@datatable.empty?
450
+
end
451
+
end
452
+
```
453
+
454
+
or
455
+
456
+
```ruby
457
+
classPostsController < ApplicationController
458
+
defindex
459
+
@datatable=Effective::Datatables::Posts.new()
460
+
@datatable.empty?(view_context)
461
+
end
462
+
end
463
+
```
464
+
381
465
### Customize Filter Behaviour
382
466
383
467
This gem does its best to provide "just works" filtering of both raw SQL (table_column) and processed results (array_column) out-of-the-box.
0 commit comments