class AjaxDatatablesRails::Datatable::Datatable

Attributes

datatable[R]
options[R]

Public Class Methods

new(datatable) click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 9
def initialize(datatable)
  @datatable = datatable
  @options   = datatable.params
end

Public Instance Methods

column_by(how, what) click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 48
def column_by(how, what)
  columns.find { |simple_column| simple_column.send(how) == what }
end
columns() click to toggle source

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

# File lib/ajax-datatables-rails/datatable/datatable.rb, line 42
def columns
  @columns ||= get_param(:columns).map do |index, column_options|
    Column.new(datatable, index, column_options)
  end
end
get_param(param) click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 70
def get_param(param)
  return {} if options[param].nil?

  options[param].to_unsafe_h.with_indifferent_access
end
offset() click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 62
def offset
  options.fetch(:start, 0).to_i
end
order_by(how, what) click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 26
def order_by(how, what)
  orders.find { |simple_order| simple_order.send(how) == what }
end
orderable?() click to toggle source

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

# File lib/ajax-datatables-rails/datatable/datatable.rb, line 16
def orderable?
  options[:order].present?
end
orders() click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 20
def orders
  @orders ||= get_param(:order).map do |_, order_options|
    SimpleOrder.new(self, order_options)
  end
end
page() click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 66
def page
  (offset / per_page) + 1
end
paginate?() click to toggle source

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

# File lib/ajax-datatables-rails/datatable/datatable.rb, line 54
def paginate?
  per_page != -1
end
per_page() click to toggle source
# File lib/ajax-datatables-rails/datatable/datatable.rb, line 58
def per_page
  options.fetch(:length, 10).to_i
end
searchable?() click to toggle source

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

# File lib/ajax-datatables-rails/datatable/datatable.rb, line 32
def searchable?
  options[:search].present? && options[:search][:value].present?
end