Class: AjaxDatatablesRails::Datatable::Datatable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datatable) ⇒ Datatable

Returns a new instance of Datatable.



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

def initialize datatable
  @datatable = datatable
  @options = datatable.params
end

Instance Attribute Details

#datatableObject (readonly)

Returns the value of attribute datatable.



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

def datatable
  @datatable
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#column_by(how, what) ⇒ Object



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

def column_by how, what
  columns.find { |simple_column| simple_column.send(how) == what }
end

#columnsObject

—————– COLUMN METHODS ——————–



40
41
42
43
44
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 40

def columns
  @columns ||= options[:columns].map do |index, column_options|
    Column.new(datatable, index, column_options)
  end
end

#offsetObject



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

def offset
  (page - 1) * per_page
end

#order_by(how, what) ⇒ Object



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

def order_by(how, what)
  orders.find { |simple_order| simple_order.send(how) == what }
end

#orderable?Boolean

—————– ORDER METHODS ——————–

Returns:

  • (Boolean)


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

def orderable?
  options[:order].present?
end

#ordersObject



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

def orders
  @orders ||= options[:order].map { |index, order_options| SimpleOrder.new(self, order_options) }
end

#pageObject



60
61
62
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 60

def page
  (options[:start].to_i / per_page) + 1
end

#paginate?Boolean

—————– OPTIONS METHODS ——————–

Returns:

  • (Boolean)


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

def paginate?
  per_page != -1
end

#per_pageObject



64
65
66
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 64

def per_page
  options.fetch(:length, 10).to_i
end

#searchObject



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

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

#searchable?Boolean

—————– SEARCH METHODS ——————–

Returns:

  • (Boolean)


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

def searchable?
  options[:search].present? && options[:search][:value].present?
end