Module: ActiveadminTableFooter::TableForExtension

Defined in:
lib/activeadmin_table_footer/table_for_extension.rb

Instance Method Summary collapse

Instance Method Details

#build(obj, *attrs) ⇒ Object



5
6
7
8
9
# File 'lib/activeadmin_table_footer/table_for_extension.rb', line 5

def build(obj, *attrs)
  options = attrs.extract_options!
  @footer_data_proc = options.delete(:footer_data)
  super(obj, *attrs, options)
end

#column(*args, &block) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/activeadmin_table_footer/table_for_extension.rb', line 26

def column(*args, &block)
  super
  col = @columns.last

  if @aatf_footer_row
    # Tfoot already exists — every subsequent column gets a cell
    # (with content if it has :footer, empty otherwise) so columns align.
    build_footer_cell_for(col)
  elsif column_has_footer?(col)
    # First column with :footer — open tfoot and back-fill empty cells
    # for all previously-added columns so the row aligns with headers.
    ensure_tfoot!
    @columns[0...-1].each { |prior| build_footer_cell_for(prior) }
    build_footer_cell_for(col)
  end
end


11
12
13
14
15
# File 'lib/activeadmin_table_footer/table_for_extension.rb', line 11

def footer_data
  return @footer_data if defined?(@footer_data)
  return (@footer_data = nil) unless @footer_data_proc
  @footer_data = @footer_data_proc.call(unscoped_collection_for_footer)
end

The collection AA passes us is the paginated + ordered slice. Aggregates over “all rows” need the underlying relation without LIMIT/OFFSET/ORDER —otherwise SUM/COUNT on page 2 would only see the page-2 slice and ORDER confuses some aggregate queries.



21
22
23
24
# File 'lib/activeadmin_table_footer/table_for_extension.rb', line 21

def unscoped_collection_for_footer
  return @collection unless @collection.respond_to?(:except)
  @collection.except(:limit, :offset, :order)
end