class AjaxDatatablesRails::Datatable::Column
Constants
- DB_ADAPTER_TYPE_CAST
- TYPE_CAST_DEFAULT
- TYPE_CAST_MYSQL
- TYPE_CAST_ORACLE
- TYPE_CAST_SQLITE
- TYPE_CAST_SQLSERVER
Attributes
datatable[R]
index[R]
options[R]
search[W]
Public Class Methods
new(datatable, index, options)
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 31 def initialize(datatable, index, options) @datatable = datatable @index = index @options = options @view_column = datatable.view_columns[options[:data].to_sym] end
Public Instance Methods
custom_field?()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 58 def custom_field? !source.include?('.') end
data()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 38 def data options[:data].presence || options[:name] end
field()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 54 def field @field ||= source.split('.').last.to_sym end
formatted_value()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 68 def formatted_value formatter ? formatter.call(search.value) : search.value end
formatter()
click to toggle source
Add formatter option to allow modification of the value before passing it to the database
# File lib/ajax-datatables-rails/datatable/column.rb, line 64 def formatter @view_column[:formatter] end
model()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 50 def model @model ||= source.split('.').first.constantize end
source()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 42 def source @view_column[:source] end
table()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 46 def table model.respond_to?(:arel_table) ? model.arel_table : model end
Private Instance Methods
casted_column()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 78 def casted_column @casted_column ||= ::Arel::Nodes::NamedFunction.new('CAST', [table[field].as(type_cast)]) end
type_cast()
click to toggle source
# File lib/ajax-datatables-rails/datatable/column.rb, line 74 def type_cast @type_cast ||= DB_ADAPTER_TYPE_CAST.fetch(AjaxDatatablesRails.config.db_adapter, TYPE_CAST_DEFAULT) end