Class: AjaxDatatablesRails::Datatable::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/ajax-datatables-rails/datatable/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datatable, index, options) ⇒ Column

Returns a new instance of Column.



6
7
8
9
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 6

def initialize(datatable, index, options)
  @datatable, @index, @options = datatable, index, options
  @view_column = datatable.view_columns[options["data"].to_sym]
end

Instance Attribute Details

#datatableObject (readonly)

Returns the value of attribute datatable.



4
5
6
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4

def datatable
  @datatable
end

#indexObject (readonly)

Returns the value of attribute index.



4
5
6
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4

def index
  @index
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4

def options
  @options
end

Instance Method Details

#condObject



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

def cond
  @view_column[:cond] || :like
end

#dataObject



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

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

#fieldObject



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

def field
  source.split('.').last.to_sym
end

#filter(value) ⇒ Object



35
36
37
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 35

def filter value
  @view_column[:cond].call self
end

#orderable?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 19

def orderable?
  options[:orderable] == TRUE_VALUE
end

#searchObject



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

def search
  @search ||= SimpleSearch.new(options[:search])
end

#search=(value) ⇒ Object



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

def search= value
  @search = value
end

#search_queryObject



52
53
54
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 52

def search_query
  search.regexp? ? regex_search : non_regex_search
end

#searchable?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 15

def searchable?
  options[:searchable] == TRUE_VALUE
end

#sort_queryObject



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

def sort_query
  if custom_field?
    source
  else
    "#{ table.name }.#{ field }"
  end
end

#sourceObject



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

def source
  @view_column[:source]
end

#tableObject



43
44
45
46
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 43

def table
  model = source.split('.').first.constantize
  model.arel_table rescue model
end