Pagy is the ultimate pagination gem that outperforms the others in each and every benchmark and comparison.
- Lower ruby requirements (ruby 1.9+ || jruby 1.7+) make Pagy very convenient also on older systems
- Added RFC-8288 compliant http response
headers
extra - The i18n internal implementation now includes full dynamic support for multi-language apps, it's ~18x faster and uses ~10x less memory than the i18n gem
- The
searchkick
andelasticsearch_rails
extras have been refactored with more and better options - Pagy 2.0+ is even faster and lighter than 1.0+ (see charts below)
The best way to quickly get an idea about Pagy is comparing it to the other well known gems.
The values shown in the charts below have been recorded while each gem was producing the exact same output in the exact same environment. (see the Detailed Gems Comparison)
Each dot in the chart represents the resources that Pagy consumes for one full rendering. The other gems consume hundreds of times as much for the same rendering.
The IPS/Kb ratio is calculated out of speed (IPS) and Memory (Kb): it shows how well each gem uses each Kb of memory it allocates/consumes.
- Pagy has a very slim core code of just ~100 lines of simple ruby, organized in 3 flat modules, very easy to understand and use (see more...)
- It has a quite fat set of optional extras that you can explicitly require for very efficient and modular customization (see extras)
- It has no dependencies: it produces its own HTML, URLs, i18n with its own specialized and fast code (see why...)
- 100% of its methods are public API, accessible and overridable right where you use them (no pesky monkey-patching needed)
- 100% test coverage for core code and extras
- The
Pagy
class doesn't need to know anything about your models, ORM or storage, so it doesn't add any code to them (see why...) - It works with all kinds of collections, even pre-paginated, records, Arrays, JSON data... and just any list, even if you cannot count it (see how...)
- Pagy works with the most popular Rack frameworks (Rails, Sinatra, Padrino, ecc.) out of the box (see more...)
- It works also with any possible non-Rack environment by just overriding one or two two-lines methods (see more...)
- Pagy is very modular and does not load nor execute unnecessary code in your app (see why...)
- It works even with collections/scopes that already used
limit
andoffset
(see how...) - It works with fast helpers OR easy to edit templates (see more...)
- It raises real
Pagy::OverflowError
exceptions that you can rescue from (see how...) or use the overflow extra for a few ready to use common behaviors - It does not impose any difficult-to-override logic or output (see why...)
- It also works on legacy systems starting from ruby 1.9+ and jruby 1.7+
You can use Pagy in a quite familiar way:
Paginate your collection in some controller:
@pagy, @records = pagy(Product.some_scope)
Render the navigation links with a super-fast helper in some view:
<%== pagy_nav(@pagy) %>
Or - if you prefer - render the navigation links with a template:
<%== render 'pagy/nav', locals: {pagy: @pagy} %>
(see Quick Start for more details)
Use the official extras, or write your own in just a few lines. Extras add special options and manage different components, behaviors, Frontend or Backend environments... usually by just requiring them:
- array: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
- countless: Paginate without the need of any count, saving one query per rendering
- elasticsearch_rails: Paginate
ElasticsearchRails
response objects - searchkick: Paginate
Searchkick::Results
objects
- bootstrap: Add nav, responsive and compact helpers for the Bootstrap pagination component
- bulma: Add nav, responsive and compact helpers for the Bulma CSS pagination component
- foundation: Add nav, responsive and compact helpers for the Foundation pagination component
- materialize: Add nav responsive and compact helpers for the Materialize CSS pagination component
- plain: Add responsive and compact plain/unstyled helpers
- semantic: Add nav, responsive and compact helpers for the Semantic UI CSS pagination component
- headers: Add RFC-8288 compliant http response headers (and other helpers) useful for API pagination
- i18n: Use the
I18n
gem instead of the pagy-i18n implementation - items: Allow the client to request a custom number of items per page with an optional selector UI
- overflow: Allow for easy handling of overflowing pages
- support: Extra support for features like: incremental, auto-incremental and infinite pagination
- trim: Remove the
page=1
param from the first page link
Besides the classic pagination nav
, Pagy offers a few ready to use alternatives like:
-
compact nav: An alternative UI that combines the pagination feature with the navigation info in one compact element:
-
responsive nav: A classic looking UI that fits the number of page links to the available width on the client-side:
Notice: the pagy_nav_bootstrap
helper used in the screencast has been renamed as pagy_bootstrap_nav
in version 2.0
- Migrating from WillPaginate and Kaminari (practical guide)
- Pagination with Pagy by Tiago Franco
- Stateful Tabs with Pagy by Chris Seelus
- Quick guide for Pagy with Sinatra and Sequel by Victor Afanasev
- Integrating Pagy with Hanami by Paweł Świątkowski
- Detailed Gems Comparison (charts and analysis)
- Benchmarks and Memory Profiles Source (Rails app repository)
- 日本語の投稿
Pagy follows the Semantic Versioning 2.0.0. Please, check the Changelog for breaking changes introduced by mayor versions.
The master
branch is the latest rubygem-published release. It also contains docs and comment changes that don't affect the published code.
The dev
branch is the development branch with the new code that will be merged in the next release.
Expect any other branch to be experimental, force-rebased and/or deleted even without merging.
Many thanks to:
- GoRails for the great Pagy Screencast and their top notch Rails Episodes
- Imaginary Cloud for continually publishing high-interest articles and helping to share Pagy when it just started
- JetBrains for their free OpenSource license
- The Contributors for all the smart code and suggestions merged in the project
- The Stargazers for showing their support
This project is available as open source under the terms of the MIT License.