-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding the pagination_count option for index page #2283 #2333
adding the pagination_count option for index page #2283 #2333
Conversation
Coverage increased (+0%) when pulling a7b387a38c1a0b7e9c60127e60d0956814e9ddd7 on joseluistorres:issue_with_count_for_big_tables_2283 into ec99964 on gregbell:master. |
Given 100 posts exist | ||
When I am on the index page for posts | ||
Then I should see pagination with 2 pages | ||
And I should not see "Displaying Posts 1 - 10 of 100 in total" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add an extra constraint that also checks the expected string:
Then I should see "Displaying Posts 1 - 10"
And I should not see "Displaying Posts 1 - 10 of 100 in total"
The reason why your code was still causing the SELECT COUNT(*) query to occur was because the variable that holds the value was still being assigned, even if the string output wasn't using it. I did a bit of a rewrite to achieve this: if collection.num_pages < 2
# ...
else
offset = (collection.current_page - 1) * collection.limit_value
if @display_total
total = collection.total_count
I18n.t 'active_admin.pagination.multiple', :model => entries_name, :total => total,
:from => offset + 1, :to => offset + collection_size
else
I18n.t 'active_admin.pagination.multiple_without_count', :model => entries_name,
:from => offset + 1, :to => offset + collection_size
end
end With def build(collection, options = {})
@collection = collection
@param_name = options.delete(:param_name)
@download_links = options.delete(:download_links)
@display_total = options.delete(:pagination_count) { true } |
Now that I really think about it, it might be better to use As well, the actual Ruby option might be better named as |
@daxter branch updated... |
Coverage increased (+0%) when pulling 6aba6a4f4b3087a353ecffb8398a09ffa02d210c on joseluistorres:issue_with_count_for_big_tables_2283 into ec99964 on gregbell:master. |
When I am on the index page for posts | ||
Then I should see pagination with 2 pages | ||
Then I should see "Displaying Posts 1 - 30" | ||
And I should not see "Displaying Posts 1 - 10 of 100 in total" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does one say 1 - 30
while the other says 1 - 10
?
Also, could you add a newline to this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, it was a typo
@daxter not sure what's wrong with the build. I bunch of failures from activeadmin.comments:
|
Sorry, I was on vacation. Can you try rebasing this on master to see if that fixes these tests? |
Cool. One more thing, though. Can you add an example to the docs in the Index Pagination section? Something like this would be great:
|
You added to the bottom of the file, but could you put it inside the "Index Pagination" section? |
LOL good point, I guess I never read that DOC before :) |
Once you get that updated, I'll gladly merge this. |
…_tables_2283 adding the pagination_count option for index page #2283
Thanks for the contribution! |
Sorry I don't understand , kaminari still use count according to logs, this do nothing except of hiding displaying of total count in view. Manual says that it should disable SELECT COUNT(*) queries |
Perhaps what you're seeing is caused by scopes you have on your index page? |
no, I have no scopes. ActiveAdmin.register IpAddress do
belongs_to :company, :optional => true
index :pagination_total => false do
column :company
column :ip
column :date_time , :sortable => :updated_at do |row|
row.updated_at
end
default_actions
end
controller do
def scoped_collection
super.includes(:company)
end
def permitted_params
params.permit ip_address: [:ip, :company_id]
end
end
end
|
@daxter Please provide feedback, I still don't know if I create enough tests.
For #2283