Class: ActiveAdmin::Views::PaginatedCollection
- Inherits:
-
Component
- Object
- Arbre::Component
- Component
- ActiveAdmin::Views::PaginatedCollection
- Defined in:
- lib/active_admin/views/components/paginated_collection.rb
Overview
Wraps the content with pagination and available formats.
Example:
paginated_collection collection, entry_name: "Post" do
div do
h2 "Inside the
end
end
This will create a div with a sentence describing the number of posts in one of the following formats:
-
“No Posts found”
-
“Displaying all 10 Posts”
-
“Displaying Posts 1 - 30 of 31 in total”
It will also generate pagination links.
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
-
#add_child(*args, &block) ⇒ Object
Override add_child to insert all children into the @contents div.
-
#build(collection, options = {}) ⇒ Object
Builds a new paginated collection component.
Methods included from Helpers::Collection
#collection_is_empty?, #collection_size
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
30 31 32 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 30 def collection @collection end |
Instance Method Details
#add_child(*args, &block) ⇒ Object
Override add_child to insert all children into the @contents div
59 60 61 62 63 64 65 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 59 def add_child(*args, &block) if @built @contents.add_child(*args, &block) else super end end |
#build(collection, options = {}) ⇒ Object
Builds a new paginated collection component
collection => A paginated collection from kaminari options => These options will be passed to ‘page_entries_info`
entry_name => The name to display for this resource collection
params => Extra parameters for pagination (e.g. { anchor: 'details' })
param_name => Parameter name for page number in the links (:page by default)
download_links => Download links override (false or [:csv, :pdf])
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 41 def build(collection, = {}) @collection = collection @params = .delete(:params) @param_name = .delete(:param_name) @download_links = .delete(:download_links) @display_total = .delete(:pagination_total) { true } @per_page = .delete(:per_page) unless collection.respond_to?(:total_pages) raise(StandardError, "Collection is not a paginated scope. Set collection.page(params[:page]).per(10) before calling :paginated_collection.") end @contents = div(class: "paginated_collection_contents") build_pagination_with_formats() @built = true end |