Class: AjaxDatatablesRails::Datatable::Column
- Inherits:
-
Object
- Object
- AjaxDatatablesRails::Datatable::Column
- Includes:
- DateFilter, Order, Search
- Defined in:
- lib/ajax-datatables-rails/datatable/column.rb,
lib/ajax-datatables-rails/datatable/column/order.rb,
lib/ajax-datatables-rails/datatable/column/search.rb,
lib/ajax-datatables-rails/datatable/column/date_filter.rb
Defined Under Namespace
Modules: DateFilter, Order, Search
Constant Summary
Constants included from DateFilter
Constants included from Search
Search::EMPTY_VALUE, Search::LARGEST_PQ_INTEGER, Search::NOT_NULL_VALUE, Search::SMALLEST_PQ_INTEGER
Instance Attribute Summary collapse
-
#datatable ⇒ Object
readonly
Returns the value of attribute datatable.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#search ⇒ Object
writeonly
Sets the attribute search.
Instance Method Summary collapse
- #column_name ⇒ Object
- #custom_field? ⇒ Boolean
- #data ⇒ Object
- #field ⇒ Object
- #formatted_value ⇒ Object
-
#formatter ⇒ Object
Add formatter option to allow modification of the value before passing it to the database.
-
#initialize(datatable, index, options) ⇒ Column
constructor
A new instance of Column.
- #model ⇒ Object
- #source ⇒ Object
- #table ⇒ Object
Methods included from DateFilter
#date_range_search, #delimiter, #empty_range_search?, #range_end, #range_start
Methods included from Order
#nulls_last?, #orderable?, #sort_field, #sort_query
Methods included from Search
#cond, #filter, #search, #search_query, #searchable?, #searched?, #use_regex?
Constructor Details
#initialize(datatable, index, options) ⇒ Column
Returns a new instance of Column.
14 15 16 17 18 19 20 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 14 def initialize(datatable, index, ) @datatable = datatable @index = index @options = @view_column = datatable.view_columns[column_name] validate_settings! end |
Instance Attribute Details
#datatable ⇒ Object (readonly)
Returns the value of attribute datatable.
11 12 13 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11 def datatable @datatable end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
11 12 13 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11 def index @index end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11 def @options end |
#search=(value) ⇒ Object (writeonly)
Sets the attribute search
12 13 14 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 12 def search=(value) @search = value end |
Instance Method Details
#column_name ⇒ Object
22 23 24 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 22 def column_name @column_name ||= [:data]&.to_sym end |
#custom_field? ⇒ Boolean
46 47 48 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 46 def custom_field? !source.include?('.') end |
#data ⇒ Object
26 27 28 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 26 def data [:data].presence || [:name] end |
#field ⇒ Object
42 43 44 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 42 def field @field ||= custom_field? ? source : source.split('.').last.to_sym end |
#formatted_value ⇒ Object
56 57 58 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 56 def formatted_value formatter ? formatter.call(search.value) : search.value end |
#formatter ⇒ Object
Add formatter option to allow modification of the value before passing it to the database
52 53 54 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 52 def formatter @view_column[:formatter] end |
#model ⇒ Object
38 39 40 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 38 def model @model ||= custom_field? ? source : source.split('.').first.constantize end |
#source ⇒ Object
30 31 32 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 30 def source @view_column[:source] end |
#table ⇒ Object
34 35 36 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 34 def table model.respond_to?(:arel_table) ? model.arel_table : model end |