class UiBibz::Ui::Ux::Tables::TablePaginationPerPage

Create a select pagination per page

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Ux::Tables::TablePaginationPerPage.new(store: @store)

Helper

table_pagination_per_page(options = {})

Public Class Methods

new(options = nil, html_options = nil) click to toggle source

Initialize per_page_field with component item per_page_field require WillPaginate gem

# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 31
def initialize(options = nil, html_options = nil)
  @per_page_field = UiBibz::Ui::Core::Component.new nil, options, html_options
end

Public Instance Methods

render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 36
def render
  if @per_page_field.options[:wrap_form] == false
    per_page_html
  else
    form_tag(url_for(url_parameters), method: :get) do
      per_page_html_in_wrap
    end
  end
end

Private Instance Methods

default_parameters?(key) click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 88
def default_parameters?(key)
  %w[store_id search controller action page link_type utf8].include?(key)
end
from_current_results() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 80
def from_current_results
  store.limit_value * store.current_page - store.limit_value + 1
end
per_page_html() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 56
def per_page_html
  content_tag :div, class: 'table-pagination-per-page' do
    concat results_count_html
    concat UiBibz::Utils::Internationalization.new('ui_bibz.table.pagination.per_page', default: 'Per page: ').translate
    concat select_tag('per_page', options_for_select([5, 10, 20, 30, 50, 100, 200, 500], store.per_page), class: 'form-select')
  end
end
per_page_html_in_wrap() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 64
def per_page_html_in_wrap
  content_tag :div, class: 'table-pagination-per-page' do
    concat results_count_html
    concat UiBibz::Utils::Internationalization.new('ui_bibz.table.pagination.per_page', default: 'Per page: ').translate
    store.parameters.with_indifferent_access.reject { |k, v| default_parameters?(k) || v.blank? }.each do |k, v|
      concat tag(:input, type: 'hidden', name: k, value: v)
    end
    concat select_tag('per_page', options_for_select([5, 10, 20, 30, 50, 100, 200, 500], store.per_page), class: 'form-select')
    concat tag(:input, type: 'hidden', name: 'store_id', value: store.id) unless store.id.nil? # If there is more 1 table in html page
  end
end
results_count_html() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 76
def results_count_html
  "#{page_entries_info store.records} | ".html_safe
end
store() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 48
def store
  @store ||= Store.new @per_page_field.options[:store]
end
to_current_results() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 84
def to_current_results
  store.limit_value * store.current_page
end
url_parameters() click to toggle source
# File lib/ui_bibz/ui/ux/tables/table_pagination_per_page.rb, line 52
def url_parameters
  { controller: store.controller, action: store.action, id: store.param_id }
end