Permalink
Browse files

Merge pull request #359 from vladimir-vg/padding-pages-count-fix

Fix wrong pagination when used with padding
  • Loading branch information...
amatsuda committed Apr 23, 2013
2 parents 533993f + 855f85e commit ee5954f6dcbb57afaf1ff369754ecf4b50de02db
Showing with 12 additions and 2 deletions.
  1. +12 −2 lib/kaminari/models/page_scope_methods.rb
@@ -15,14 +15,19 @@ def per(num)
end
def padding(num)
+ @_padding = num
offset(offset_value + num.to_i)
end
# Total number of pages
def total_pages
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
max_pages
else
@@ -35,7 +40,12 @@ def total_pages
# Current page number
def current_page
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
# First page of the collection ?

0 comments on commit ee5954f

Please sign in to comment.