Class: AjaxDatatablesRails::Datatable::Datatable
- Inherits:
-
Object
- Object
- AjaxDatatablesRails::Datatable::Datatable
- Defined in:
- lib/ajax-datatables-rails/datatable/datatable.rb
Instance Attribute Summary collapse
-
#datatable ⇒ Object
readonly
Returns the value of attribute datatable.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #column_by(how, what) ⇒ Object
-
#columns ⇒ Object
—————– COLUMN METHODS ——————–.
-
#initialize(datatable) ⇒ Datatable
constructor
A new instance of Datatable.
- #offset ⇒ Object
- #order_by(how, what) ⇒ Object
-
#orderable? ⇒ Boolean
—————– ORDER METHODS ——————–.
- #orders ⇒ Object
- #page ⇒ Object
-
#paginate? ⇒ Boolean
—————– OPTIONS METHODS ——————–.
- #per_page ⇒ Object
- #search ⇒ Object
-
#searchable? ⇒ Boolean
—————– SEARCH METHODS ——————–.
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
#datatable ⇒ Object (readonly)
Returns the value of attribute datatable.
7 8 9 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 7 def datatable @datatable end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 7 def @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 |
#columns ⇒ Object
—————– COLUMN METHODS ——————–
40 41 42 43 44 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 40 def columns @columns ||= [:columns].map do |index, | Column.new(datatable, index, ) end end |
#offset ⇒ Object
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 ——————–
16 17 18 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 16 def orderable? [:order].present? end |
#orders ⇒ Object
20 21 22 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 20 def orders @orders ||= [:order].map { |index, | SimpleOrder.new(self, ) } end |
#page ⇒ Object
60 61 62 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 60 def page ([:start].to_i / per_page) + 1 end |
#paginate? ⇒ Boolean
—————– OPTIONS METHODS ——————–
52 53 54 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 52 def paginate? per_page != -1 end |
#per_page ⇒ Object
64 65 66 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 64 def per_page .fetch(:length, 10).to_i end |
#search ⇒ Object
34 35 36 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 34 def search @search ||= SimpleSearch.new([:search]) end |
#searchable? ⇒ Boolean
—————– SEARCH METHODS ——————–
30 31 32 |
# File 'lib/ajax-datatables-rails/datatable/datatable.rb', line 30 def searchable? [:search].present? && [:search][:value].present? end |