Class: Effective::Datatable
- Inherits:
-
Object
- Object
- Effective::Datatable
- Extended by:
- EffectiveDatatable::Dsl
- Includes:
- EffectiveDatatable::Attributes, EffectiveDatatable::Collection, EffectiveDatatable::Compute, EffectiveDatatable::Cookie, EffectiveDatatable::Format, EffectiveDatatable::Hooks, EffectiveDatatable::Params, EffectiveDatatable::Resource, EffectiveDatatable::State
- Defined in:
- app/models/effective/datatable.rb
Constant Summary
Constants included from EffectiveDatatable::Format
EffectiveDatatable::Format::BLANK
Constants included from EffectiveDatatable::Compute
EffectiveDatatable::Compute::BLANK
Instance Attribute Summary collapse
-
#_aggregates ⇒ Object
readonly
Hashes of DSL options.
-
#_bulk_actions ⇒ Object
readonly
Returns the value of attribute _bulk_actions.
-
#_charts ⇒ Object
readonly
Returns the value of attribute _charts.
-
#_collection ⇒ Object
The collection itself.
-
#_columns ⇒ Object
readonly
Returns the value of attribute _columns.
-
#_filters ⇒ Object
readonly
Returns the value of attribute _filters.
-
#_form ⇒ Object
readonly
Returns the value of attribute _form.
-
#_scopes ⇒ Object
readonly
Returns the value of attribute _scopes.
-
#attributes ⇒ Object
readonly
Anything that we initialize our table with.
-
#cookie ⇒ Object
readonly
The view, and the ajax/cookie/default state.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#view ⇒ Object
Returns the value of attribute view.
Instance Method Summary collapse
-
#_filters_form_required? ⇒ Boolean
Whether the filters must be rendered as a <form> or we can keep the normal <div> behaviour.
- #blank?(view = nil) ⇒ Boolean
- #collection ⇒ Object
- #columns ⇒ Object
- #dsl_tool ⇒ Object
-
#initialize(view = nil, attributes = {}) ⇒ Datatable
constructor
A new instance of Datatable.
- #present?(view = nil) ⇒ Boolean
-
#simple? ⇒ Boolean
When simple only a table will be rendered with no sorting, no filtering, no export buttons, no pagination, no per page, no colReorder default sorting only, default visibility only, all records returned, and responsive enabled.
- #table_html_class ⇒ Object
- #to_json ⇒ Object
- #to_param ⇒ Object
Methods included from EffectiveDatatable::Dsl
bulk_actions, charts, datatable, filters
Methods included from EffectiveDatatable::State
#display_length, #display_start, #filter, #order_direction, #order_index, #order_name, #page, #per_page, #scope, #search
Methods included from EffectiveDatatable::Resource
#admin_namespace?, #controller_namespace
Methods included from EffectiveDatatable::Hooks
Methods included from EffectiveDatatable::Cookie
Methods included from EffectiveDatatable::Collection
#active_record_collection?, #array_collection?, #collection_class
Constructor Details
#initialize(view = nil, attributes = {}) ⇒ Datatable
Returns a new instance of Datatable.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/effective/datatable.rb', line 35 def initialize(view = nil, attributes = {}) (attributes = view; view = nil) if view.kind_of?(Hash) @attributes = initial_attributes(attributes) @state = initial_state @_aggregates = {} @_bulk_actions = [] @_charts = {} @_columns = {} @_filters = {} @_form = {} @_scopes = {} raise 'collection is defined as a method. Please use the collection do ... end syntax.' unless collection.nil? self.view = view if view end |
Instance Attribute Details
#_aggregates ⇒ Object (readonly)
Hashes of DSL options
8 9 10 |
# File 'app/models/effective/datatable.rb', line 8 def _aggregates @_aggregates end |
#_bulk_actions ⇒ Object (readonly)
Returns the value of attribute _bulk_actions.
9 10 11 |
# File 'app/models/effective/datatable.rb', line 9 def _bulk_actions @_bulk_actions end |
#_charts ⇒ Object (readonly)
Returns the value of attribute _charts.
10 11 12 |
# File 'app/models/effective/datatable.rb', line 10 def _charts @_charts end |
#_collection ⇒ Object
The collection itself. Only evaluated once.
17 18 19 |
# File 'app/models/effective/datatable.rb', line 17 def _collection @_collection end |
#_columns ⇒ Object (readonly)
Returns the value of attribute _columns.
11 12 13 |
# File 'app/models/effective/datatable.rb', line 11 def _columns @_columns end |
#_filters ⇒ Object (readonly)
Returns the value of attribute _filters.
12 13 14 |
# File 'app/models/effective/datatable.rb', line 12 def _filters @_filters end |
#_form ⇒ Object (readonly)
Returns the value of attribute _form.
13 14 15 |
# File 'app/models/effective/datatable.rb', line 13 def _form @_form end |
#_scopes ⇒ Object (readonly)
Returns the value of attribute _scopes.
14 15 16 |
# File 'app/models/effective/datatable.rb', line 14 def _scopes @_scopes end |
#attributes ⇒ Object (readonly)
Anything that we initialize our table with. That’s it. Can’t be changed by state.
3 4 5 |
# File 'app/models/effective/datatable.rb', line 3 def attributes @attributes end |
#cookie ⇒ Object (readonly)
The view, and the ajax/cookie/default state
20 21 22 |
# File 'app/models/effective/datatable.rb', line 20 def @cookie end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'app/models/effective/datatable.rb', line 4 def resource @resource end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
5 6 7 |
# File 'app/models/effective/datatable.rb', line 5 def state @state end |
#view ⇒ Object
Returns the value of attribute view.
21 22 23 |
# File 'app/models/effective/datatable.rb', line 21 def view @view end |
Instance Method Details
#_filters_form_required? ⇒ Boolean
Whether the filters must be rendered as a <form> or we can keep the normal <div> behaviour
126 127 128 |
# File 'app/models/effective/datatable.rb', line 126 def _filters_form_required? _form[:verb].present? end |
#blank?(view = nil) ⇒ Boolean
95 96 97 98 99 100 101 102 103 |
# File 'app/models/effective/datatable.rb', line 95 def blank?(view = nil) unless (@view || view) raise 'unable to call blank? without an assigned view. In your view, either call render_datatable(@datatable) first, or use @datatable.blank?(self)' end self.view ||= view to_json[:recordsTotal] == 0 end |
#collection ⇒ Object
142 143 144 |
# File 'app/models/effective/datatable.rb', line 142 def collection @_collection end |
#columns ⇒ Object
138 139 140 |
# File 'app/models/effective/datatable.rb', line 138 def columns @_columns end |
#dsl_tool ⇒ Object
146 147 148 |
# File 'app/models/effective/datatable.rb', line 146 def dsl_tool @dsl_tool ||= DatatableDslTool.new(self) end |
#present?(view = nil) ⇒ Boolean
85 86 87 88 89 90 91 92 93 |
# File 'app/models/effective/datatable.rb', line 85 def present?(view = nil) unless (@view || view) raise 'unable to call present? without an assigned view. In your view, either call render_datatable(@datatable) first, or use @datatable.present?(self)' end self.view ||= view to_json[:recordsTotal] > 0 end |
#simple? ⇒ Boolean
When simple only a table will be rendered with no sorting, no filtering, no export buttons, no pagination, no per page, no colReorder default sorting only, default visibility only, all records returned, and responsive enabled
121 122 123 |
# File 'app/models/effective/datatable.rb', line 121 def simple? attributes[:simple] == true end |
#table_html_class ⇒ Object
130 131 132 |
# File 'app/models/effective/datatable.rb', line 130 def table_html_class attributes[:class] || 'table table-bordered table-striped' end |
#to_json ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'app/models/effective/datatable.rb', line 105 def to_json @json ||= ( { data: (compute || []), draw: (params[:draw] || 0), recordsTotal: (@total_records || 0), recordsFiltered: (@display_records || 0), aggregates: (@aggregates_data || []), charts: (@charts_data || {}) } ) end |
#to_param ⇒ Object
134 135 136 |
# File 'app/models/effective/datatable.rb', line 134 def to_param @to_param ||= self.class.name.underscore.parameterize end |