Issue #412 paginated collection scope #428

Merged
merged 4 commits into from Sep 29, 2011

Projects

None yet

3 participants

@samvincent

Adding support for the following features. These were driven by the desire to display multiple paginated collections on one page in the show action. Targets Issue #412.

  • Fix scope issue with :collection method call for #paginated_entries_info
  • Add support for :param_name option
  • Add support for :download_links => false
samvincent added some commits Aug 26, 2011
@samvincent samvincent Issue #412 - Fix scope issue with :collection for PaginatedCollection…
… component

When rendering a PaginatedCollection for an associated collection within the
show context (for example), the :collection method called was referring to the resource
rather than the passed in collection. Also raising error if collection has not been
scoped with Kaminari to help new users figure it out.
c6813b5
@samvincent samvincent Issue #412 - Added support for :param_name to PaginatedCollection
Setting :param_name allows you to put multiple paginated collections
on a single page. (eg. Show action)
1d3895a
@samvincent samvincent Issue #412 - Disable download links option for PaginatedCollection
When rendering a paginated collection on the show screen for example,
it does not make sense to include resource download links for the collection.
2043acb
@samvincent samvincent Issue #412 - Fix for broken cuke complaining of unsymbolized key 3027431
@gregbell gregbell merged commit 3027431 into activeadmin:master Sep 29, 2011
@acurley

I cannot seem to get multiple paginated collections to work properly (i.e. paginate) on one show view. Could someone post an example of their show action that successfully renders multiple tables with pagination?

@samvincent

You'll want to set your param name if you're doing multiple paginated collections.

div :id => "items" do
  collection = resource.items.page(params[:item_page]).per(15)
  pagination_options = {:entry_name => Item.model_name.human, :param_name => :item_page, :download_links => false}
  paginated_collection(collection, pagination_options) do
    table_options = { :id => 'items-table', :sortable => true, :class => "index_table", :i18n => Item }
    table_for collection, table_options do
      column(:code)      { |resource| resource.item.code }
      column(:name)      { |resource| resource.item.name }
      column :created_at
    end
  end
end
@acurley

Thanks! That was very helpful! The only problem that remains is that the "Display Items" information at the top right of the table still defaults to 1-30 despite my use of .per(15). The pagination buttons on the bottom right still increment in groups of 15, but the numbers in the top right are not correct. For a class of objects that has 194 "items", the last page of paginated hits says "Displaying Items 361 - 194 of 194 in total". I'm guessing that .per(15) in this instance does not override system defaults.

@samvincent

That stuff has to do with Kaminari. You may want to take a look there and inspect your collection. I've been getting the expected results for my paginated collections so far.

@acurley

It looks like it is actually a default behavior in lib/active_admin/views/components/paginated_collection.rb. I don't see how my .per method overwrites the active_admin_application.default_per_page.

def page_entries_info(options = {})
  if collection.num_pages < 2
    ....
  else
    offset = collection.current_page * active_admin_application.default_per_page
    total  = collection.total_count
    I18n.t('active_admin.pagination.multiple', :model => entry_name.pluralize, :from => (offset - active_admin_application.default_per_page + 1), :to => offset > total ? total : offset, :total => total)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment