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”
-
“Showing all 10 Posts”
-
“Showing 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.
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
26 27 28 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 26 def collection @collection end |
Instance Method Details
#add_child(*args, &block) ⇒ Object
Override add_child to insert all children into the @contents div
55 56 57 58 59 60 61 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 55 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])
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_admin/views/components/paginated_collection.rb', line 37 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 add_class "paginated-collection" @contents = div(class: "paginated-collection-contents") build_pagination_with_formats() @built = true end |