class Voom::Presenters::DSL::Components::Table::Pagination
Attributes
current_page[RW]
page_size[RW]
per_page[RW]
total[RW]
Public Class Methods
new(**attribs_, &block)
click to toggle source
Calls superclass method
Voom::Presenters::DSL::Components::Base::new
# File lib/voom/presenters/dsl/components/table.rb, line 119 def initialize(**attribs_, &block) super(type: :pagination, **attribs_, &block) @page_size = attribs.delete(:page_size){10}.to_i @page_size_options = attribs.delete(:page_size_options){[10,20,30,40,50,100]} @total = attribs.delete(:total) @current_page = attribs.delete(:current_page){ 1 }.to_i @replace_id = attribs.delete(:replace_id) @replace_presenter = attribs.delete(:replace_presenter) previous_button_icon next_button_icon per_page_select range expand! end
Public Instance Methods
per_page_select()
click to toggle source
# File lib/voom/presenters/dsl/components/table.rb, line 151 def per_page_select return @per_page if locked? @per_page = select(@page_size_options, @page_size, @total) end
range()
click to toggle source
# File lib/voom/presenters/dsl/components/table.rb, line 134 def range return @range if locked? end_range = @total - (@total - @page_size * @current_page.to_i) start_range = end_range - @page_size + 1 @range = [start_range, end_range] end
Private Instance Methods
select(options, current_option, total_records, replace_id = @replace_id, replace_presenter = @replace_presenter)
click to toggle source
# File lib/voom/presenters/dsl/components/table.rb, line 171 def select(options, current_option, total_records, replace_id = @replace_id, replace_presenter = @replace_presenter) __attribs__ = attribs.reject{ |key,val| [:page_size, :page].include? key } Components::Select.new(parent: self, name: :page_size, full_width: false) do options.each do |num| option selected: (num == current_option) do text num value num end break if num > total_records end event :change do replaces replace_id, replace_presenter, __attribs__.merge(page_size: context[:page_size]) end end end
total_pages()
click to toggle source
# File lib/voom/presenters/dsl/components/table.rb, line 158 def total_pages (@total.to_f / @page_size.to_f).ceil end