Class: AjaxDatatablesRails::Datatable::Column
- Inherits:
-
Object
- Object
- AjaxDatatablesRails::Datatable::Column
- Defined in:
- lib/ajax-datatables-rails/datatable/column.rb
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.
Instance Method Summary collapse
- #cond ⇒ Object
- #data ⇒ Object
- #field ⇒ Object
- #filter(value) ⇒ Object
-
#initialize(datatable, index, options) ⇒ Column
constructor
A new instance of Column.
- #orderable? ⇒ Boolean
- #search ⇒ Object
- #search=(value) ⇒ Object
- #search_query ⇒ Object
- #searchable? ⇒ Boolean
- #sort_query ⇒ Object
- #source ⇒ Object
- #table ⇒ Object
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, ) @datatable, @index, @options = datatable, index, @view_column = datatable.view_columns[["data"].to_sym] end |
Instance Attribute Details
#datatable ⇒ Object (readonly)
Returns the value of attribute datatable.
4 5 6 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4 def datatable @datatable end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
4 5 6 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4 def index @index end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 4 def @options end |
Instance Method Details
#cond ⇒ Object
31 32 33 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 31 def cond @view_column[:cond] || :like end |
#data ⇒ Object
11 12 13 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 11 def data [:data].presence || [:name] end |
#field ⇒ Object
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
19 20 21 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 19 def orderable? [:orderable] == TRUE_VALUE end |
#search ⇒ Object
23 24 25 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 23 def search @search ||= SimpleSearch.new([: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_query ⇒ Object
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
15 16 17 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 15 def searchable? [:searchable] == TRUE_VALUE end |
#sort_query ⇒ Object
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 |
#source ⇒ Object
39 40 41 |
# File 'lib/ajax-datatables-rails/datatable/column.rb', line 39 def source @view_column[:source] end |
#table ⇒ Object
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 |