activeadmin_table_footer
Adds a <tfoot> row to ActiveAdmin index tables. Totals are aggregated
across all pages of the filtered scope — not just the visible one — in a
single SQL query when you use footer_data:.
Works with ActiveAdmin 3.5+ and 4.x.
ActiveAdmin 4

ActiveAdmin 3

The page shows 30 rows, but the footer row reports the sum across all 42 subscriptions — that's the point.
Install
# Gemfile
gem "activeadmin_table_footer"
Usage
ActiveAdmin.register Subscription do
index footer_data: ->(collection) {
totals = collection.joins(:plan).pick(
Arel.sql("COALESCE(SUM(seats), 0)"),
Arel.sql("COALESCE(SUM(seats * plans.monthly_price), 0)")
)
{ total_seats: totals[0], total_cost: totals[1] }
} do
column :customer
column :plan
column :is_operator, footer: -> { strong { "Total (all pages)" } }
column "Seats", footer: -> { strong { [:total_seats].to_s } }, &:seats
column :total_cost, footer: -> { strong { number_to_currency([:total_cost]) } } do |row|
number_to_currency row.total_cost
end
end
end
The footer_data: Proc runs once over the filtered scope (LIMIT/OFFSET/ORDER
are stripped automatically). The result is exposed inside each
column …, footer: … Proc via footer_data.
footer: accepts a string, a symbol (:sum, :count, :average,
:minimum, :maximum), or a Proc — Procs run inside the table view, so view
helpers (number_to_currency, link_to) and Arbre tags (strong, span)
work as expected.
License
MIT