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::Resource
EffectiveDatatable::Resource::AGGREGATE_SQL_FUNCTIONS
Constants included from EffectiveDatatable::Format
EffectiveDatatable::Format::BLANK
Constants included from EffectiveDatatable::Cookie
EffectiveDatatable::Cookie::MAX_COOKIE_SIZE
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.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#view ⇒ Object
The 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, #offset, #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
#cookie, #cookie_key, #cookie_keys, #cookie_param
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/effective/datatable.rb', line 34 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 |
#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
The view
20 21 22 |
# File 'app/models/effective/datatable.rb', line 20 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
128 129 130 |
# File 'app/models/effective/datatable.rb', line 128 def _filters_form_required? _form[:verb].present? end |
#blank?(view = nil) ⇒ Boolean
97 98 99 100 101 102 103 104 105 |
# File 'app/models/effective/datatable.rb', line 97 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
144 145 146 |
# File 'app/models/effective/datatable.rb', line 144 def collection @_collection end |
#columns ⇒ Object
140 141 142 |
# File 'app/models/effective/datatable.rb', line 140 def columns @_columns end |
#dsl_tool ⇒ Object
148 149 150 |
# File 'app/models/effective/datatable.rb', line 148 def dsl_tool @dsl_tool ||= DatatableDslTool.new(self) end |
#present?(view = nil) ⇒ Boolean
87 88 89 90 91 92 93 94 95 |
# File 'app/models/effective/datatable.rb', line 87 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
123 124 125 |
# File 'app/models/effective/datatable.rb', line 123 def simple? attributes[:simple] == true end |
#table_html_class ⇒ Object
132 133 134 |
# File 'app/models/effective/datatable.rb', line 132 def table_html_class attributes[:class] || EffectiveDatatables.html_class end |
#to_json ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'app/models/effective/datatable.rb', line 107 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
136 137 138 |
# File 'app/models/effective/datatable.rb', line 136 def to_param @to_param ||= "#{self.class.name.underscore.parameterize}-#{}" end |