Class: AjaxDatatablesRails::Datatable::SimpleOrder

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

Constant Summary collapse

DIRECTION_ASC =
'ASC'
DIRECTION_DESC =
'DESC'
DIRECTIONS =
[DIRECTION_ASC, DIRECTION_DESC].freeze

Instance Method Summary collapse

Constructor Details

#initialize(datatable, options = {}) ⇒ SimpleOrder

Returns a new instance of SimpleOrder.



11
12
13
14
15
16
# File 'lib/ajax-datatables-rails/datatable/simple_order.rb', line 11

def initialize(datatable, options = {})
  @datatable  = datatable
  @options    = options
  @adapter    = datatable.db_adapter
  @nulls_last = datatable.nulls_last
end

Instance Method Details

#columnObject



22
23
24
# File 'lib/ajax-datatables-rails/datatable/simple_order.rb', line 22

def column
  @datatable.column_by(:index, column_index)
end

#directionObject



26
27
28
# File 'lib/ajax-datatables-rails/datatable/simple_order.rb', line 26

def direction
  DIRECTIONS.find { |dir| dir == column_direction } || DIRECTION_ASC
end

#query(sort_column) ⇒ Object



18
19
20
# File 'lib/ajax-datatables-rails/datatable/simple_order.rb', line 18

def query(sort_column)
  [sort_column, direction, nulls_last_sql].compact.join(' ')
end