Skip to content

Commit

Permalink
Merge pull request #359 from vladimir-vg/padding-pages-count-fix
Browse files Browse the repository at this point in the history
Fix wrong pagination when used with padding
  • Loading branch information
amatsuda committed Apr 23, 2013
2 parents 533993f + 855f85e commit ee5954f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/kaminari/models/page_scope_methods.rb
Expand Up @@ -15,14 +15,19 @@ def per(num)
end end


def padding(num) def padding(num)
@_padding = num
offset(offset_value + num.to_i) offset(offset_value + num.to_i)
end end


# Total number of pages # Total number of pages
def total_pages def total_pages
return 1 if limit_value.nil? return 1 if limit_value.nil?


total_pages_count = (total_count.to_f / limit_value).ceil count_without_padding = total_count
count_without_padding -= @_padding if @_padding
count_without_padding = 0 if count_without_padding < 0

total_pages_count = (count_without_padding.to_f / limit_value).ceil
if max_pages.present? && max_pages < total_pages_count if max_pages.present? && max_pages < total_pages_count
max_pages max_pages
else else
Expand All @@ -35,7 +40,12 @@ def total_pages
# Current page number # Current page number
def current_page def current_page
return 1 if limit_value.nil? return 1 if limit_value.nil?
(offset_value / limit_value) + 1
offset_without_padding = offset_value
offset_without_padding -= @_padding if @_padding
offset_without_padding = 0 if offset_without_padding < 0

(offset_without_padding / limit_value) + 1
end end


# First page of the collection ? # First page of the collection ?
Expand Down

0 comments on commit ee5954f

Please sign in to comment.