Class: Acts::DataTable::SortableColumns::Renderers::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_data_table/sortable_columns/renderers/default.rb

Direct Known Subclasses

Bootstrap2, Bootstrap3

Instance Method Summary collapse

Constructor Details

#initialize(sortable, action_view) ⇒ Default

Returns a new instance of Default.



19
20
21
22
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 19

def initialize(sortable, action_view)
  @action_view = action_view
  @sortable    = sortable
end

Instance Method Details

#captionString

Returns The column header’s caption.

Returns:

  • (String)

    The column header’s caption



35
36
37
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 35

def caption
  @sortable.caption
end

Returns a link to toggle a column.

Returns:

  • (String)

    a link to toggle a column



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 53

def caption_link
  link_options                              = @sortable.html_options.clone
  link_options['data-init']                 = 'sortable-column'
  link_options['data-remote']               = @sortable.remote
  link_options['data-url-toggle']           = @sortable.urls.toggle
  link_options['data-url-set-base']         = @sortable.urls.set_base
  link_options['data-url-change-direction'] = @sortable.urls.change_direction
  link_options['data-active']               = 'true' if @sortable.active

  @action_view.link_to(@sortable.caption, '#', link_options)
end

#direction_indicatorString

Returns an indicator about the sorting direction for the current column. The direction is either ‘ASC’ or ‘DESC’.

Returns:

  • (String)

    an indicator about the sorting direction for the current column. The direction is either ‘ASC’ or ‘DESC’



28
29
30
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 28

def direction_indicator
  @sortable.direction == 'ASC' ? 'Δ' : '∇'
end

Returns a link to change the sorting direction for an already active column.

Returns:

  • (String)

    a link to change the sorting direction for an already active column



42
43
44
45
46
47
48
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 42

def direction_link
  link_options                              = @sortable.html_options.clone
  link_options['data-init']                 = 'sortable-column-direction'
  link_options['data-remote']               = @sortable.remote
  link_options['data-url-change-direction'] = @sortable.urls.change_direction
  @action_view.link_to(direction_indicator, '#', link_options)
end

#to_htmlString

Generates the actual HTML (= caption and direction links) to be embedded into the view

Returns:

  • (String)

    the generated HTML code



71
72
73
74
75
76
77
# File 'lib/acts_as_data_table/sortable_columns/renderers/default.rb', line 71

def to_html
  if @sortable.active
    caption_link + ' ' + direction_link
  else
    caption_link
  end
end