lib/magic_grid/collection.rb in magic_grid-0.12.0 vs lib/magic_grid/collection.rb in magic_grid-0.12.1
- old
+ new
@@ -11,10 +11,11 @@
listener_handler: nil,
default_col: 0,
default_order: :asc,
post_filter: false,
collection_post_filter: true,
+ count: nil,
}
def initialize(collection, opts = {})
@collection = collection || []
self.options = opts
@@ -36,10 +37,14 @@
def options=(opts)
@options = DEFAULTS.merge(opts || {})
end
+ def count_options
+ @options[:count]
+ end
+
def self.create_or_reuse(collection, opts = {})
if collection.is_a?(self)
collection.options = opts
collection
else
@@ -165,11 +170,11 @@
end
def count(collection = nil)
count_or_hash = collection || @collection
while count_or_hash.respond_to? :count
- count_or_hash = count_or_hash.count
+ count_or_hash = count_or_hash.send :count, *(Array([count_options]).compact)
end
count_or_hash
end
def per_page=(n)
@@ -201,10 +206,10 @@
def perform_pagination(collection)
return collection unless @per_page
if collection.respond_to? :paginate
- collection.paginate(page: @current_page, per_page: @per_page)
+ collection.paginate(page: @current_page, per_page: @per_page, total_entries: count(collection))
elsif collection.respond_to? :page
collection.page(@current_page).per(@per_page)
elsif collection.is_a?(Array) and Module.const_defined?(:Kaminari)
Kaminari.paginate_array(collection).page(@current_page).per(@per_page)
else