How to Add Pagination with Pagy Discussion
I found this gem a couple of months ago and I don't see myself going back to kaminari, really good work!
Hi chris, Domizio,
I have not managed to get pagy to work with searchkick (implemented as the searchkick episode). getting weird message as it seems to be looking for a total_count method. I am in Rails 5.2. Thks much for your help.
Hey Stan X,
Check out the pagy_searchkick extra - https://ddnexus.github.io/pagy/extras/searchkick
@pagy_s, @employees = pagy_searchkick (
policy_scope(Employee).search(query,
{
misspellings: {fields: [:department]},
order: {created_at: :desc},
load: true,
per_page: 40
}
I have some results. trouble is that my policy_scope from pundit does not apply anymore if i do this.
following this note from Stephen Dolan, I did something which provides the results but...to be fair it is dirty...(and i don't know what i am doing!)
query = params[:search].presence || "*"
@pagy_s, @employees = pagy_searchkick (
policy_scope(Employee).search(query,
{
misspellings: {fields: [:department]},
order: {created_at: :desc},
load: true,
per_page: 40,
scope_results: ->(r) { r.where(id: policy_scope(Employee).pluck(:id)) }
}
)
)
And the pagination from pagy does not work anymore...:-(
Think I have an issue. Appreciate is someone could help to combine 3 things:
- pagy
- searchkick
- pundit probably never heard off outside Gorails but Chris is introducing too much nice gems. Question: how to make them work together.
The searchkick extra has been refactored in pagy v2.0. If you need more support, please use the gitter chat. Thanks.
Thank you for this wonderful explanation. The Pagy docs don't mention the requirement that you need to 'import' the methods for front end and back end. This video was the missing link. Thank you once again Chris for a job well done!
I certainly agree with the "Chris... job well done": indeed I couldn't have explained it better, but let me point out that the Pagy docs does mention it everywhere it makes sense:
Hi Domizio,
Thank you for this. My team and I only found the Quick Start doc. We must have missed the other docs. If you haven't already, perhaps post these four links prominently at the top of the read me? Maybe they are there, but we couldn't get it to work until we watched Chris' video. Not a criticism: just helpful (we hope) feedback from actual users. We love Pagy and thank you so much for creating it!
-Monroe
BreakDiving.io
Pagy 3.0 is out!
Now ~40x faster, ~36x lighter!
Take a look at the charts ;)
Oh that's exciting! Since we just got the prior version working, will it be easy to upgrade? Do you recommend we do so, or stick with what we now have working? Thanks Domizio.
Monroe, 3.0 is better than 2.0 and 1.0, obviously :)
Depending on what you used in 2.0, you might be OK even without changing anything in your code, and if you have to change something it will probably be just search and replace, (some method and variable have been renamed). Please, check the CHANGELOG for complete details.
The elasticsearch extras refactoring mentioned by Tabish happened in 2.0, and 3.0 didn't touch it.
Thank you Chris, for another awesome and clear explanation. And thank you Domizio for making Pagy.
👏
If we are counting records, ie. <%= index + 1%> how can we keep the count going when we we navigate to the next page? Currently my next page starts at 1 again.
Hi everyone. I just installed pagy and it's working fine, but I'm having a problem with the bootstrap extension. When I create the pagy.rb and add this line of code: require 'pagy/extras/bootstrap'
I'm having this error: "`require': cannot load such file -- pagy/extras/bootstrap (LoadError)". Anyone knows what could be the problem here?
Thanks!