Class: Grapple::Components::KaminariInfobar
- Inherits:
-
HtmlComponent
- Object
- BaseComponent
- HtmlComponent
- Grapple::Components::KaminariInfobar
- Defined in:
- lib/grapple/components/kaminari_infobar.rb
Instance Attribute Summary
Attributes inherited from BaseComponent
#builder, #columns, #params, #records, #template
Instance Method Summary collapse
Methods inherited from BaseComponent
Constructor Details
This class inherits a constructor from Grapple::Components::BaseComponent
Instance Method Details
#render ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/grapple/components/kaminari_infobar.rb', line 9 def render estimate = false begin # total_count will throw an error if without_count is being used total_count = records.total_count rescue Exception => e estimate = true total_count = ActiveRecord::Base.connection.execute( "SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = '#{records.table_name}'" ).first["approximate_row_count"].to_i end if total_count > 0 offset = (records.current_page - 1) * records.current_per_page start_range = offset + 1 end_range = [offset + records.current_per_page, total_count].min start_range = ActiveSupport::NumberHelper.number_to_delimited(start_range) end_range = ActiveSupport::NumberHelper.number_to_delimited(end_range) total = ActiveSupport::NumberHelper.number_to_delimited(total_count) html = sprintf((estimate ? : ), start_range, end_range, total) else html = end builder.row "<th colspan=\"#{num_columns}\">#{html}</th>", :class => 'infobar' end |