Class: Aureus::Components::DataTable

Inherits:
Renderable show all
Includes:
ActionView::Helpers::JavaScriptHelper
Defined in:
lib/aureus/components/data_table.rb

Instance Method Summary collapse

Methods inherited from Renderable

#compact, #compact_render, #content_tag, #init

Constructor Details

#initialize(resource) ⇒ DataTable

Returns a new instance of DataTable.



8
9
10
11
12
# File 'lib/aureus/components/data_table.rb', line 8

def initialize resource
  @resource = resource
  @head = DataTableHead.new
  @rows = Array.new
end

Instance Method Details

#dataObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/aureus/components/data_table.rb', line 26

def data
  {
    i18n_sSearch: I18n.t('aureus.datatables.search'),
    i18n_sLengthMenu: I18n.t('aureus.datatables.length_menu'),
    i18n_sZeroRecords: I18n.t('aureus.datatables.zero_records'),
    i18n_sInfo: I18n.t('aureus.datatables.info'),
    i18n_sInfoEmpty: I18n.t('aureus.datatables.info_empty'),
    i18n_sInfoFiltered: I18n.t('aureus.datatables.info_filtered')
  }
end

#head {|@head| ... } ⇒ Object

Yields:



14
15
16
# File 'lib/aureus/components/data_table.rb', line 14

def head
  yield @head
end

#renderObject



37
38
39
40
41
# File 'lib/aureus/components/data_table.rb', line 37

def render
   'table', id: @resource.class.name.downcase, class: 'datatable', data: data do
    compact @head.render, ('tbody',compact_render(*@rows))
  end
end

#rowObject



18
19
20
21
22
23
24
# File 'lib/aureus/components/data_table.rb', line 18

def row
  @resource.each do |r|
    row = DataTableRow.new
    yield row, r
    @rows << row
  end
end