8000 Merge pull request #3879 from knu/pagination_params · stephancom/activeadmin@c82d732 · GitHub
[go: up one dir, main page]

Skip to content

Commit c82d732

Browse files
committed
Merge pull request activeadmin#3879 from knu/pagination_params
Add a `:params` option to PaginatedCollection.
2 parents 28e8a8f + f29652a commit c82d732

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/active_admin/views/components/paginated_collection.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class PaginatedCollection < ActiveAdmin::Component
3232
# collection => A paginated collection from kaminari
3333
# options => These options will be passed to `page_entries_info`
3434
# entry_name => The name to display for this resource collection
35+
# params => Extra parameters for pagination (e.g. { anchor: 'details' })
3536
# param_name => Parameter name for page number in the links (:page by default)
3637
# download_links => Download links override (false or [:csv, :pdf])
3738
#
3839
def build(collection, options = {})
3940
@collection = collection
41+
@params = options.delete(:params)
4042
@param_name = options.delete(:param_name)
4143
@download_links = options.delete(:download_links)
4244
@display_total = options.delete(:pagination_total) { true }
@@ -95,6 +97,7 @@ def build_per_page_select
9597

9698
def build_pagination
9799
options = {}
100+
options[:params] = @params if @params
98101
options[:param_name] = @param_name if @param_name
99102

100103
text_node paginate collection, options

spec/unit/views/components/paginated_collection_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ def paginated_collection(*args)
6565
end
6666
end
6767

68+
context "when specifying :params option" do
69+
let(:collection) do
70+
posts = 10.times.map{ Post.new }
71+
Kaminari.paginate_array(posts).page(1).per(5)
72+
end
73+
74+
let(:pagination) { paginated_collection(collection, param_name: :post_page, params: { anchor: 'here' }) }
75+
76+
it "should pass it through to Kaminari" do
77+
expect(pagination.children.last.content).to match(/\/admin\/posts\?post_page=2#here/)
78+
end
79+
end
80+
6881
context "when specifying download_links: false option" do
6982
let(:collection) do
7083
posts = 10.times.map{ Post.new }

0 commit comments

Comments
 (0)
0