Class: AjaxDatatablesRails::Datatable::Column

Inherits:
Object
  • Object
show all
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

DateFilter::RANGE_DELIMITER

Constants included from Search

Search::EMPTY_VALUE, Search::LARGEST_PQ_INTEGER, Search::NOT_NULL_VALUE, Search::SMALLEST_PQ_INTEGER

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options)
  @datatable   = datatable
  @index       = index
  @options     = options
  @view_column = datatable.view_columns[column_name]
  validate_settings!
end

Instance Attribute Details

#datatableObject (readonly)

Returns the value of attribute datatable.



11
12
13
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11

def datatable
  @datatable
end

#indexObject (readonly)

Returns the value of attribute index.



11
12
13
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11

def index
  @index
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11

def options
  @options
end

#search=(value) ⇒ Object (writeonly)

Sets the attribute search

Parameters:

  • value

    the value to set the attribute search to.



12
13
14
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 12

def search=(value)
  @search = value
end

Instance Method Details

#column_nameObject



22
23
24
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 22

def column_name
  @column_name ||= options[:data]&.to_sym
end

#custom_field?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 46

def custom_field?
  !source.include?('.')
end

#dataObject



26
27
28
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 26

def data
  options[:data].presence || options[:name]
end

#fieldObject



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_valueObject



56
57
58
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 56

def formatted_value
  formatter ? formatter.call(search.value) : search.value
end

#formatterObject

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

#modelObject



38
39
40
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 38

def model
  @model ||= custom_field? ? source : source.split('.').first.constantize
end

#sourceObject



30
31
32
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 30

def source
  @view_column[:source]
end

#tableObject



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